mirror of
https://github.com/UberGames/lilium-voyager.git
synced 2024-11-10 06:31:47 +00:00
OpenGL2: Replace r_exportCubemaps cvar with exportCubemaps command.
This commit is contained in:
parent
a6a6162f04
commit
c3216f54d2
4 changed files with 99 additions and 39 deletions
|
@ -1737,6 +1737,65 @@ const void *RB_PostProcess(const void *data)
|
|||
return (const void *)(cmd + 1);
|
||||
}
|
||||
|
||||
// FIXME: put this function declaration elsewhere
|
||||
void R_SaveDDS(const char *filename, byte *pic, int width, int height, int depth);
|
||||
|
||||
/*
|
||||
=============
|
||||
RB_ExportCubemaps
|
||||
|
||||
=============
|
||||
*/
|
||||
const void *RB_ExportCubemaps(const void *data)
|
||||
{
|
||||
const exportCubemapsCommand_t *cmd = data;
|
||||
|
||||
// finish any 2D drawing if needed
|
||||
if (tess.numIndexes)
|
||||
RB_EndSurface();
|
||||
|
||||
if (!glRefConfig.framebufferObject || !tr.world || tr.numCubemaps == 0)
|
||||
{
|
||||
// do nothing
|
||||
ri.Printf(PRINT_ALL, "Nothing to export!\n");
|
||||
return (const void *)(cmd + 1);
|
||||
}
|
||||
|
||||
if (cmd)
|
||||
{
|
||||
FBO_t *oldFbo = glState.currentFBO;
|
||||
int sideSize = CUBE_MAP_SIZE * CUBE_MAP_SIZE * 4;
|
||||
byte *cubemapPixels = ri.Malloc(sideSize * 6);
|
||||
int i, j;
|
||||
|
||||
FBO_Bind(tr.renderCubeFbo);
|
||||
|
||||
for (i = 0; i < tr.numCubemaps; i++)
|
||||
{
|
||||
char filename[MAX_QPATH];
|
||||
cubemap_t *cubemap = &tr.cubemaps[i];
|
||||
char *p = cubemapPixels;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Com_sprintf(filename, MAX_QPATH, "cubemaps/%s/%03d.dds", tr.world->baseName, i);
|
||||
R_SaveDDS(filename, cubemapPixels, CUBE_MAP_SIZE, CUBE_MAP_SIZE, 6);
|
||||
ri.Printf(PRINT_ALL, "Saved cubemap %d as %s\n", i, filename);
|
||||
}
|
||||
|
||||
FBO_Bind(oldFbo);
|
||||
|
||||
ri.Free(cubemapPixels);
|
||||
}
|
||||
|
||||
return (const void *)(cmd + 1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
====================
|
||||
|
@ -1785,6 +1844,9 @@ void RB_ExecuteRenderCommands( const void *data ) {
|
|||
case RC_POSTPROCESS:
|
||||
data = RB_PostProcess(data);
|
||||
break;
|
||||
case RC_EXPORT_CUBEMAPS:
|
||||
data = RB_ExportCubemaps(data);
|
||||
break;
|
||||
case RC_END_OF_LIST:
|
||||
default:
|
||||
// finish any 2D drawing if needed
|
||||
|
|
|
@ -3067,13 +3067,9 @@ 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++)
|
||||
|
@ -3081,9 +3077,6 @@ void R_RenderAllCubemaps(void)
|
|||
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++)
|
||||
|
@ -3093,34 +3086,6 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -142,7 +142,6 @@ cvar_t *r_specularMapping;
|
|||
cvar_t *r_deluxeMapping;
|
||||
cvar_t *r_parallaxMapping;
|
||||
cvar_t *r_cubeMapping;
|
||||
cvar_t *r_exportCubemaps;
|
||||
cvar_t *r_specularIsMetallic;
|
||||
cvar_t *r_glossIsRoughness;
|
||||
cvar_t *r_baseNormalX;
|
||||
|
@ -832,6 +831,35 @@ void R_ScreenShotJPEG_f (void) {
|
|||
|
||||
//============================================================================
|
||||
|
||||
/*
|
||||
==================
|
||||
R_ExportCubemaps
|
||||
==================
|
||||
*/
|
||||
void R_ExportCubemaps()
|
||||
{
|
||||
exportCubemapsCommand_t *cmd;
|
||||
|
||||
cmd = R_GetCommandBuffer(sizeof(*cmd));
|
||||
if (!cmd) {
|
||||
return;
|
||||
}
|
||||
cmd->commandId = RC_EXPORT_CUBEMAPS;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==================
|
||||
R_ExportCubemaps_f
|
||||
==================
|
||||
*/
|
||||
void R_ExportCubemaps_f(void)
|
||||
{
|
||||
R_ExportCubemaps();
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
||||
/*
|
||||
==================
|
||||
RB_TakeVideoFrameCmd
|
||||
|
@ -1215,7 +1243,6 @@ void R_Register( void )
|
|||
r_deluxeMapping = ri.Cvar_Get( "r_deluxeMapping", "1", CVAR_ARCHIVE | CVAR_LATCH );
|
||||
r_parallaxMapping = ri.Cvar_Get( "r_parallaxMapping", "0", CVAR_ARCHIVE | CVAR_LATCH );
|
||||
r_cubeMapping = ri.Cvar_Get( "r_cubeMapping", "0", CVAR_ARCHIVE | CVAR_LATCH );
|
||||
r_exportCubemaps = ri.Cvar_Get("r_exportCubemaps", "0", 0);
|
||||
r_specularIsMetallic = ri.Cvar_Get( "r_specularIsMetallic", "0", CVAR_ARCHIVE | CVAR_LATCH );
|
||||
r_glossIsRoughness = ri.Cvar_Get("r_glossIsRoughness", "0", CVAR_ARCHIVE | CVAR_LATCH);
|
||||
r_baseNormalX = ri.Cvar_Get( "r_baseNormalX", "1.0", CVAR_ARCHIVE | CVAR_LATCH );
|
||||
|
@ -1355,6 +1382,7 @@ void R_Register( void )
|
|||
ri.Cmd_AddCommand( "gfxinfo", GfxInfo_f );
|
||||
ri.Cmd_AddCommand( "minimize", GLimp_Minimize );
|
||||
ri.Cmd_AddCommand( "gfxmeminfo", GfxMemInfo_f );
|
||||
ri.Cmd_AddCommand( "exportCubemaps", R_ExportCubemaps_f );
|
||||
}
|
||||
|
||||
void R_InitQueries(void)
|
||||
|
@ -1500,6 +1528,7 @@ void RE_Shutdown( qboolean destroyWindow ) {
|
|||
ri.Cmd_RemoveCommand( "modelist" );
|
||||
ri.Cmd_RemoveCommand( "shaderstate" );
|
||||
ri.Cmd_RemoveCommand( "gfxmeminfo" );
|
||||
ri.Cmd_RemoveCommand( "exportCubemaps" );
|
||||
|
||||
|
||||
if ( tr.registered ) {
|
||||
|
|
|
@ -1792,7 +1792,6 @@ extern cvar_t *r_specularMapping;
|
|||
extern cvar_t *r_deluxeMapping;
|
||||
extern cvar_t *r_parallaxMapping;
|
||||
extern cvar_t *r_cubeMapping;
|
||||
extern cvar_t *r_exportCubemaps;
|
||||
extern cvar_t *r_specularIsMetallic;
|
||||
extern cvar_t *r_glossIsRoughness;
|
||||
extern cvar_t *r_baseNormalX;
|
||||
|
@ -2420,6 +2419,10 @@ typedef struct {
|
|||
viewParms_t viewParms;
|
||||
} postProcessCommand_t;
|
||||
|
||||
typedef struct {
|
||||
int commandId;
|
||||
} exportCubemapsCommand_t;
|
||||
|
||||
typedef enum {
|
||||
RC_END_OF_LIST,
|
||||
RC_SET_COLOR,
|
||||
|
@ -2432,7 +2435,8 @@ typedef enum {
|
|||
RC_COLORMASK,
|
||||
RC_CLEARDEPTH,
|
||||
RC_CAPSHADOWMAP,
|
||||
RC_POSTPROCESS
|
||||
RC_POSTPROCESS,
|
||||
RC_EXPORT_CUBEMAPS
|
||||
} renderCommand_t;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue