From 19c44d9c50d6a3057e79007c779552d0eb7fe4ef Mon Sep 17 00:00:00 2001 From: SmileTheory Date: Tue, 22 Dec 2015 05:04:07 -0800 Subject: OpenGL2: Add r_exportCubemaps for saving cubemaps on map load. --- src/renderergl2/tr_image_dds.c | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/renderergl2/tr_image_dds.c') 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); +} -- cgit