Ejemplo n.º 1
0
GBitmap *AtlasTexChunk::loadDDSIntoGBitmap(const U8 *ddsBuffer, U32 ddsBufferSize)
{
    D3DXIMAGE_INFO info;
    D3D9Assert(GFXD3DX.D3DXGetImageInfoFromFileInMemory(ddsBuffer, ddsBufferSize, &info),
               "AtlasTexChunk::loadDDSIntoGBitmap - failed to get image info.");

    IDirect3DSurface9 *surf = NULL;
    D3D9Assert(((GFXD3D9Device*)GFX)->getDevice()->CreateOffscreenPlainSurface(
                   info.Width, info.Height, info.Format, D3DPOOL_SCRATCH, &surf, NULL),
               "AtlasTexChunk::loadDDSIntoGBitmap - failed to allocate scratch surface.");

    // We want JPEGs, let's convert it in a klunky way...
    D3D9Assert(GFXD3DX.D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL,
               ddsBuffer, ddsBufferSize, NULL,
               D3DX_DEFAULT, 0, NULL),
               "AtlasTexChunk::loadDDSIntoGBitmap - D3DX failed to load from buffer.");

    ID3DXBuffer *buff = NULL;
    D3D9Assert(GFXD3DX.D3DXSaveSurfaceToFileInMemory(&buff, D3DXIFF_PNG, surf, NULL, NULL),
               "AtlasTexChunk::loadDDSIntoGBitmap - D3DX failed to save back to buffer.");
    MemStream ms(buff->GetBufferSize(), buff->GetBufferPointer(), true, false);

    GBitmap *bitmap = new GBitmap[1];
    bitmap->readBitmap( "png", ms );

    // Cleanup!
    buff->Release();
    surf->Release();

    return bitmap;
}
bool blTerrainChunk::read(Stream & stream)
{
   if(!Parent::read(stream))
      return(false);

   mLightmap = new GBitmap();
   return mLightmap->readBitmap("png",stream);
}