diff options
author | SmileTheory <SmileTheory@gmail.com> | 2015-12-22 05:04:07 -0800 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2016-04-07 11:46:05 +0100 |
commit | 19c44d9c50d6a3057e79007c779552d0eb7fe4ef (patch) | |
tree | e3bb41cd085c1b1c4851bd4daf593f3322a523ef /src/renderergl2/tr_image_dds.c | |
parent | e78dc015d1c94fbe4fa5014d412a2cdf23f2dc7d (diff) |
OpenGL2: Add r_exportCubemaps for saving cubemaps on map load.
Diffstat (limited to 'src/renderergl2/tr_image_dds.c')
-rw-r--r-- | src/renderergl2/tr_image_dds.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/renderergl2/tr_image_dds.c b/src/renderergl2/tr_image_dds.c index 8ad406fd..b509014d 100644 --- a/src/renderergl2/tr_image_dds.c +++ b/src/renderergl2/tr_image_dds.c @@ -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); +} |