OpenGL2: Add r_exportCubemaps for saving cubemaps on map load.

This commit is contained in:
SmileTheory 2015-12-22 05:04:07 -08:00
parent 06feb6115b
commit a6a6162f04
4 changed files with 85 additions and 1 deletions

View file

@ -451,3 +451,48 @@ void R_LoadDDS ( const char *filename, byte **pic, int *width, int *height, GLen
ri.FS_FreeFile(buffer.v);
}
void R_SaveDDS(const char *filename, byte *pic, int width, int height, int depth)
{
byte *data;
ddsHeader_t *ddsHeader;
int picSize, size;
if (!depth)
depth = 1;
picSize = width * height * depth * 4;
size = 4 + sizeof(*ddsHeader) + picSize;
data = ri.Malloc(size);
data[0] = 'D';
data[1] = 'D';
data[2] = 'S';
data[3] = ' ';
ddsHeader = (ddsHeader_t *)(data + 4);
memset(ddsHeader, 0, sizeof(ddsHeader_t));
ddsHeader->headerSize = 0x7c;
ddsHeader->flags = _DDSFLAGS_REQUIRED;
ddsHeader->height = height;
ddsHeader->width = width;
ddsHeader->always_0x00000020 = 0x00000020;
ddsHeader->caps = DDSCAPS_COMPLEX | DDSCAPS_REQUIRED;
if (depth == 6)
ddsHeader->caps2 = DDSCAPS2_CUBEMAP;
ddsHeader->pixelFormatFlags = DDSPF_RGB | DDSPF_ALPHAPIXELS;
ddsHeader->rgbBitCount = 32;
ddsHeader->rBitMask = 0x000000ff;
ddsHeader->gBitMask = 0x0000ff00;
ddsHeader->bBitMask = 0x00ff0000;
ddsHeader->aBitMask = 0xff000000;
Com_Memcpy(data + 4 + sizeof(*ddsHeader), pic, picSize);
ri.FS_WriteFile(filename, data, size);
ri.Free(data);
}