summaryrefslogtreecommitdiff
path: root/src/renderergl2/tr_bsp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderergl2/tr_bsp.c')
-rw-r--r--src/renderergl2/tr_bsp.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/renderergl2/tr_bsp.c b/src/renderergl2/tr_bsp.c
index d2a5f5f2..81463c66 100644
--- a/src/renderergl2/tr_bsp.c
+++ b/src/renderergl2/tr_bsp.c
@@ -3068,16 +3068,23 @@ void R_AssignCubemapsToWorldSurfaces(void)
}
}
+// FIXME: put this function declaration elsewhere
+void R_SaveDDS(const char *filename, byte *pic, int width, int height, int depth);
void R_RenderAllCubemaps(void)
{
+ byte *data = NULL;
+ int sideSize = CUBE_MAP_SIZE * CUBE_MAP_SIZE * 4;
int i, j;
for (i = 0; i < tr.numCubemaps; i++)
{
tr.cubemaps[i].image = R_CreateImage(va("*cubeMap%d", i), NULL, CUBE_MAP_SIZE, CUBE_MAP_SIZE, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE | IMGFLAG_MIPMAP | IMGFLAG_CUBEMAP, GL_RGBA8);
}
-
+
+ if (r_exportCubemaps->integer)
+ data = ri.Malloc(sideSize * 6);
+
for (i = 0; i < tr.numCubemaps; i++)
{
for (j = 0; j < 6; j++)
@@ -3087,6 +3094,34 @@ void R_RenderAllCubemaps(void)
R_IssuePendingRenderCommands();
R_InitNextFrame();
}
+
+ if (r_exportCubemaps->integer)
+ {
+ char filename[MAX_QPATH];
+ byte *p;
+ cubemap_t *cubemap = &tr.cubemaps[i];
+
+ // FIXME: do this in backEnd
+ FBO_Bind(tr.renderCubeFbo);
+
+ p = data;
+ for (j = 0; j < 6; j++)
+ {
+ qglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + j, cubemap->image->texnum, 0);
+ qglReadPixels(0, 0, CUBE_MAP_SIZE, CUBE_MAP_SIZE, GL_RGBA, GL_UNSIGNED_BYTE, p);
+ p += sideSize;
+ }
+ FBO_Bind(NULL);
+
+ Com_sprintf(filename, MAX_QPATH, "cubemaps/%s/%03d.dds", tr.world->baseName, backEnd.viewParms.targetFboCubemapIndex);
+ R_SaveDDS(filename, data, CUBE_MAP_SIZE, CUBE_MAP_SIZE, 6);
+ }
+ }
+
+ if (r_exportCubemaps->integer)
+ {
+ ri.Cvar_Set("r_exportCubemaps", "0");
+ ri.Free(data);
}
}