astyle and other wonderbar stuff!

This commit is contained in:
BielBdeLuna 2014-08-25 15:25:54 +02:00
parent fedaf6b691
commit fc7ed840bc
4 changed files with 233 additions and 184 deletions

View file

@ -530,7 +530,8 @@ void idCommonLocal::Frame()
// save the screenshot and audio from the last draw if needed // save the screenshot and audio from the last draw if needed
if( aviCaptureMode ) if( aviCaptureMode )
{ {
idStr name = va( "demos/%s/%s_%05i", aviDemoShortName.c_str(), aviDemoShortName.c_str(), aviDemoFrameCount++ ); idStr name;
name.Format( "demos/%s/%s_%05i", aviDemoShortName.c_str(), aviDemoShortName.c_str(), aviDemoFrameCount++ );
renderSystem->TakeScreenshot( com_aviDemoWidth.GetInteger(), com_aviDemoHeight.GetInteger(), name, com_aviDemoSamples.GetInteger(), NULL, TGA ); renderSystem->TakeScreenshot( com_aviDemoWidth.GetInteger(), com_aviDemoHeight.GetInteger(), name, com_aviDemoSamples.GetInteger(), NULL, TGA );
// remove any printed lines at the top before taking the screenshot // remove any printed lines at the top before taking the screenshot

View file

@ -69,7 +69,7 @@ typedef enum
CF_2D_ARRAY // not a cube map but not a single 2d texture either CF_2D_ARRAY // not a cube map but not a single 2d texture either
} cubeFiles_t; } cubeFiles_t;
enum fileType_t enum imageFileType_t
{ {
TGA, TGA,
PNG, PNG,

View file

@ -550,16 +550,22 @@ void R_RotatePic( byte* data, int width )
// transforms in both ways, the images from a cube map, // transforms in both ways, the images from a cube map,
// in both the Env map and the Skybox map systems. // in both the Env map and the Skybox map systems.
void R_ApplyCubeMapTransforms ( int iter, byte* data, int size ) { void R_ApplyCubeMapTransforms( int iter, byte* data, int size )
if ( ( iter == 1 ) || ( iter == 2 ) ) { {
if( ( iter == 1 ) || ( iter == 2 ) )
{
R_VerticalFlip( data, size, size ); R_VerticalFlip( data, size, size );
} }
if ( ( iter == 0 ) || ( iter == 1 ) || ( iter == 4 ) || ( iter == 5 ) ) { if( ( iter == 0 ) || ( iter == 1 ) || ( iter == 4 ) || ( iter == 5 ) )
{
R_RotatePic( data, size ); // apparently not only rotates but also flips horitzontally R_RotatePic( data, size ); // apparently not only rotates but also flips horitzontally
} }
if ( iter == 1 ) { if( iter == 1 )
{
R_VerticalFlip( data, size, size ); R_VerticalFlip( data, size, size );
} else if ( iter == 3 ) { // that's so just for having less lines }
else if( iter == 3 ) // that's so just for having less lines
{
R_HorizontalFlip( data, size, size ); R_HorizontalFlip( data, size, size );
} }
} }

View file

@ -237,7 +237,7 @@ idCVar r_shadowMapPolygonOffset( "r_shadowMapPolygonOffset", "3000", CVAR_RENDER
idCVar r_shadowMapOccluderFacing( "r_shadowMapOccluderFacing", "2", CVAR_RENDERER | CVAR_INTEGER, "0 = front faces, 1 = back faces, 2 = twosided" ); idCVar r_shadowMapOccluderFacing( "r_shadowMapOccluderFacing", "2", CVAR_RENDERER | CVAR_INTEGER, "0 = front faces, 1 = back faces, 2 = twosided" );
// RB end // RB end
const char* fileExten [3] = { "tga", "png", "jpg" }; const char* fileExten[3] = { "tga", "png", "jpg" };
const char* envDirection[6] = { "_nx", "_py", "_ny", "_pz", "_nz", "_px" }; const char* envDirection[6] = { "_nx", "_py", "_ny", "_pz", "_nz", "_px" };
const char* skyDirection[6] = { "_forward", "_back", "_left", "_right", "_up", "_down" }; const char* skyDirection[6] = { "_forward", "_back", "_left", "_right", "_up", "_down" };
@ -1231,28 +1231,33 @@ void idRenderSystemLocal::TakeScreenshot( int width, int height, const char* fil
{ {
byte* buffer; byte* buffer;
int i, j, c, temp; int i, j, c, temp;
const char *formatName[3] = { ".tga", ".png", ".jpg" };
idStr finalFileName; idStr finalFileName;
sprintf( finalFileName, "%s%s", fileName, formatName[exten] ); finalFileName.Format( "%s.%s", fileName, fileExten[exten] );
takingScreenshot = true; takingScreenshot = true;
int pix = width * height; int pix = width * height;
const int bufferSize = pix * 3 + 18; const int bufferSize = pix * 3 + 18;
if ( exten == PNG ) { if( exten == PNG )
{
buffer = ( byte* )R_StaticAlloc( pix * 3 ); buffer = ( byte* )R_StaticAlloc( pix * 3 );
} else if ( exten == TGA ) { }
buffer = (byte *)R_StaticAlloc( bufferSize ); else if( exten == TGA )
{
buffer = ( byte* )R_StaticAlloc( bufferSize );
memset( buffer, 0, bufferSize ); memset( buffer, 0, bufferSize );
} }
if( blends <= 1 ) if( blends <= 1 )
{ {
if ( exten == PNG ) { if( exten == PNG )
{
R_ReadTiledPixels( width, height, buffer, ref ); R_ReadTiledPixels( width, height, buffer, ref );
} else if ( exten == TGA ) { }
else if( exten == TGA )
{
R_ReadTiledPixels( width, height, buffer + 18, ref ); R_ReadTiledPixels( width, height, buffer + 18, ref );
} }
} }
@ -1266,17 +1271,23 @@ void idRenderSystemLocal::TakeScreenshot( int width, int height, const char* fil
for( i = 0 ; i < blends ; i++ ) for( i = 0 ; i < blends ; i++ )
{ {
if ( exten == PNG ) { if( exten == PNG )
{
R_ReadTiledPixels( width, height, buffer, ref ); R_ReadTiledPixels( width, height, buffer, ref );
} else if ( exten == TGA ) { }
else if( exten == TGA )
{
R_ReadTiledPixels( width, height, buffer + 18, ref ); R_ReadTiledPixels( width, height, buffer + 18, ref );
} }
for( j = 0 ; j < pix * 3 ; j++ ) for( j = 0 ; j < pix * 3 ; j++ )
{ {
if ( exten == PNG ) { if( exten == PNG )
{
shortBuffer[j] += buffer[j]; shortBuffer[j] += buffer[j];
} else if ( exten == TGA ) { }
else if( exten == TGA )
{
shortBuffer[j] += buffer[18 + j]; shortBuffer[j] += buffer[18 + j];
} }
} }
@ -1285,9 +1296,12 @@ void idRenderSystemLocal::TakeScreenshot( int width, int height, const char* fil
// divide back to bytes // divide back to bytes
for( i = 0 ; i < pix * 3 ; i++ ) for( i = 0 ; i < pix * 3 ; i++ )
{ {
if ( exten == PNG ) { if( exten == PNG )
{
buffer[i] = shortBuffer[i] / blends; buffer[i] = shortBuffer[i] / blends;
} else if ( exten == TGA ) { }
else if( exten == TGA )
{
buffer[18 + i] = shortBuffer[i] / blends; buffer[18 + i] = shortBuffer[i] / blends;
} }
} }
@ -1295,9 +1309,12 @@ void idRenderSystemLocal::TakeScreenshot( int width, int height, const char* fil
R_StaticFree( shortBuffer ); R_StaticFree( shortBuffer );
r_jitter.SetBool( false ); r_jitter.SetBool( false );
} }
if ( exten == PNG ) { if( exten == PNG )
{
R_WritePNG( finalFileName, buffer, 3, width, height, false ); R_WritePNG( finalFileName, buffer, 3, width, height, false );
} else { }
else
{
// fill in the header (this is vertically flipped, which qglReadPixels emits) // fill in the header (this is vertically flipped, which qglReadPixels emits)
buffer[2] = 2; // uncompressed type buffer[2] = 2; // uncompressed type
buffer[12] = width & 255; buffer[12] = width & 255;
@ -1309,10 +1326,11 @@ void idRenderSystemLocal::TakeScreenshot( int width, int height, const char* fil
// swap rgb to bgr // swap rgb to bgr
c = 18 + width * height * 3; c = 18 + width * height * 3;
for (i=18 ; i<c ; i+=3) { for( i = 18 ; i < c ; i += 3 )
{
temp = buffer[i]; temp = buffer[i];
buffer[i] = buffer[i+2]; buffer[i] = buffer[i + 2];
buffer[i+2] = temp; buffer[i + 2] = temp;
} }
fileSystem->WriteFile( finalFileName, buffer, c ); fileSystem->WriteFile( finalFileName, buffer, c );
@ -1503,40 +1521,48 @@ envshot <basename>
Saves out env/<basename>_ft.tga, etc Saves out env/<basename>_ft.tga, etc
================== ==================
*/ */
void R_EnvShot_f( const idCmdArgs &args ) { void R_EnvShot_f( const idCmdArgs& args )
{
idStr fullname; idStr fullname;
const char *baseName; const char* baseName;
int i; int i;
idMat3 axis[7], oldAxis; idMat3 axis[7], oldAxis;
renderView_t ref; renderView_t ref;
viewDef_t primary; viewDef_t primary;
int blends; int blends;
const char *extensions[7] = { "_wrong", "_nx", "_py", "_ny", "_pz", "_nz", "_px" }; const char* extension;
int size; int size;
int res_w, res_h, old_fov_x, old_fov_y; int res_w, res_h, old_fov_x, old_fov_y;
res_w = renderSystem->GetWidth(); res_w = renderSystem->GetWidth();
res_h = renderSystem->GetHeight(); res_h = renderSystem->GetHeight();
if ( args.Argc() != 2 && args.Argc() != 3 && args.Argc() != 4 ) { if( args.Argc() != 2 && args.Argc() != 3 && args.Argc() != 4 )
{
common->Printf( "USAGE: envshot <basename> [size] [blends]\n" ); common->Printf( "USAGE: envshot <basename> [size] [blends]\n" );
return; return;
} }
baseName = args.Argv( 1 ); baseName = args.Argv( 1 );
blends = 1; blends = 1;
if ( args.Argc() == 4 ) { if( args.Argc() == 4 )
{
size = atoi( args.Argv( 2 ) ); size = atoi( args.Argv( 2 ) );
blends = atoi( args.Argv( 3 ) ); blends = atoi( args.Argv( 3 ) );
} else if ( args.Argc() == 3 ) { }
else if( args.Argc() == 3 )
{
size = atoi( args.Argv( 2 ) ); size = atoi( args.Argv( 2 ) );
blends = 1; blends = 1;
} else { }
else
{
size = 256; size = 256;
blends = 1; blends = 1;
} }
if ( !tr.primaryView ) { if( !tr.primaryView )
{
common->Printf( "No primary view.\n" ); common->Printf( "No primary view.\n" );
return; return;
} }
@ -1573,26 +1599,36 @@ void R_EnvShot_f( const idCmdArgs &args ) {
axis[6][2][1] = 1; axis[6][2][1] = 1;
// let's get the game window to a "size" resolution // let's get the game window to a "size" resolution
if ( ( res_w != size ) || ( res_h != size ) ) { if( ( res_w != size ) || ( res_h != size ) )
{
cvarSystem->SetCVarInteger( "r_windowWidth", size ); cvarSystem->SetCVarInteger( "r_windowWidth", size );
cvarSystem->SetCVarInteger( "r_windowHeight", size ); cvarSystem->SetCVarInteger( "r_windowHeight", size );
R_SetNewMode( false ); // the same as "vid_restart" R_SetNewMode( false ); // the same as "vid_restart"
} // FIXME that's a hack!! } // FIXME that's a hack!!
for ( i = 0 ; i < 7 ; i++ ) { for( i = 0 ; i < 7 ; i++ )
{
ref = primary.renderView; ref = primary.renderView;
if ( i == 0 ) { if( i == 0 )
{
// so we return to that axis and fov after the fact. // so we return to that axis and fov after the fact.
oldAxis = ref.viewaxis; oldAxis = ref.viewaxis;
old_fov_x = ref.fov_x; old_fov_x = ref.fov_x;
old_fov_y = ref.fov_y; old_fov_y = ref.fov_y;
//this is part of the hack
extension = "_wrong";
}
else
{
// this keeps being part of the hack
extension = envDirection[ i - 1 ]; //yes, indeed, this is totally part of the hack!
} }
ref.fov_x = ref.fov_y = 90; ref.fov_x = ref.fov_y = 90;
ref.viewaxis = axis[i]; ref.viewaxis = axis[i];
sprintf( fullname, "env/%s%s", baseName, extensions[i] ); fullname.Format( "env/%s%s", baseName, extension );
tr.TakeScreenshot( size, size, fullname, blends, &ref, TGA ); tr.TakeScreenshot( size, size, fullname, blends, &ref, TGA );
} }
@ -1699,9 +1735,6 @@ void R_MakeAmbientMap_f( const idCmdArgs& args )
renderView_t ref; renderView_t ref;
viewDef_t primary; viewDef_t primary;
int downSample; int downSample;
const char* extensions[6] = { "_px.tga", "_nx.tga", "_py.tga", "_ny.tga",
"_pz.tga", "_nz.tga"
};
int outSize; int outSize;
byte* buffers[6]; byte* buffers[6];
int width = 0, height = 0; int width = 0, height = 0;
@ -1751,7 +1784,7 @@ void R_MakeAmbientMap_f( const idCmdArgs& args )
// read all of the images // read all of the images
for( i = 0 ; i < 6 ; i++ ) for( i = 0 ; i < 6 ; i++ )
{ {
sprintf( fullname, "env/%s%s", baseName, extensions[i] ); fullname.Format( "env/%s%s.%s", baseName, envDirection[i], fileExten[TGA] );
common->Printf( "loading %s\n", fullname.c_str() ); common->Printf( "loading %s\n", fullname.c_str() );
const bool captureToImage = false; const bool captureToImage = false;
common->UpdateScreen( captureToImage ); common->UpdateScreen( captureToImage );
@ -1826,11 +1859,11 @@ void R_MakeAmbientMap_f( const idCmdArgs& args )
if( map == 0 ) if( map == 0 )
{ {
sprintf( fullname, "env/%s_amb%s", baseName, extensions[i] ); fullname.Format( "env/%s_amb%s.%s", baseName, envDirection[i], fileExten[TGA] );
} }
else else
{ {
sprintf( fullname, "env/%s_spec%s", baseName, extensions[i] ); fullname.Format( "env/%s_spec%s.%s", baseName, envDirection[i], fileExten[TGA] );
} }
common->Printf( "writing %s\n", fullname.c_str() ); common->Printf( "writing %s\n", fullname.c_str() );
const bool captureToImage = false; const bool captureToImage = false;
@ -1852,7 +1885,6 @@ void R_TransformCubemap( const char* orgDirection[6], const char* orgDir, const
{ {
idStr fullname; idStr fullname;
int i; int i;
const char* ext = ".tga";
bool errorInOriginalImages = false; bool errorInOriginalImages = false;
int outSize; int outSize;
byte* buffers[6]; byte* buffers[6];
@ -1861,27 +1893,33 @@ void R_TransformCubemap( const char* orgDirection[6], const char* orgDir, const
for( i = 0 ; i < 6 ; i++ ) for( i = 0 ; i < 6 ; i++ )
{ {
// read every image images // read every image images
sprintf( fullname, "%s/%s%s.%s", orgDir, baseName, orgDirection[i], fileExten [TGA] ); fullname.Format( "%s/%s%s.%s", orgDir, baseName, orgDirection[i], fileExten [TGA] );
common->Printf( "loading %s\n", fullname.c_str() ); common->Printf( "loading %s\n", fullname.c_str() );
const bool captureToImage = false; const bool captureToImage = false;
common->UpdateScreen( captureToImage ); common->UpdateScreen( captureToImage );
R_LoadImage( fullname, &buffers[i], &width, &height, NULL, true ); R_LoadImage( fullname, &buffers[i], &width, &height, NULL, true );
//check if the buffer is troublesome //check if the buffer is troublesome
if ( !buffers[i] ) if( !buffers[i] )
{ {
common->Printf( "failed.\n" ); common->Printf( "failed.\n" );
errorInOriginalImages = true; errorInOriginalImages = true;
} else if ( width != height ) { }
else if( width != height )
{
common->Printf( "wrong size pal!\n\n\nget your shit together and set the size according to your images!\n\n\ninept programmers are inept!\n" ); common->Printf( "wrong size pal!\n\n\nget your shit together and set the size according to your images!\n\n\ninept programmers are inept!\n" );
errorInOriginalImages = true; // yeah, but don't just choke on a joke! errorInOriginalImages = true; // yeah, but don't just choke on a joke!
} else { }
else
{
errorInOriginalImages = false; errorInOriginalImages = false;
} }
if ( errorInOriginalImages ) { if( errorInOriginalImages )
{
errorInOriginalImages = false; errorInOriginalImages = false;
for( i-- ; i >= 0 ; i-- ) { for( i-- ; i >= 0 ; i-- )
{
Mem_Free( buffers[i] ); // clean up every buffer from this stage down Mem_Free( buffers[i] ); // clean up every buffer from this stage down
} }
@ -1892,7 +1930,7 @@ void R_TransformCubemap( const char* orgDirection[6], const char* orgDir, const
R_ApplyCubeMapTransforms( i, buffers[i], width ); R_ApplyCubeMapTransforms( i, buffers[i], width );
//save the images with the appropiate skybox naming convention //save the images with the appropiate skybox naming convention
sprintf( fullname, "%s/%s/%s%s.%s", destDir, baseName, baseName, destDirection[i], fileExten [TGA] ); fullname.Format( "%s/%s/%s%s.%s", destDir, baseName, baseName, destDirection[i], fileExten [TGA] );
common->Printf( "writing %s\n", fullname.c_str() ); common->Printf( "writing %s\n", fullname.c_str() );
common->UpdateScreen( false ); common->UpdateScreen( false );
R_WriteTGA( fullname, buffers[i], width, width ); R_WriteTGA( fullname, buffers[i], width, width );
@ -1917,9 +1955,11 @@ transforms env textures (of the type px, py, pz, nx, ny, nz)
to skybox textures ( forward, back, left, right, up, down) to skybox textures ( forward, back, left, right, up, down)
================== ==================
*/ */
void R_TransformEnvToSkybox_f( const idCmdArgs& args ){ void R_TransformEnvToSkybox_f( const idCmdArgs& args )
{
if( args.Argc() != 2 ) { if( args.Argc() != 2 )
{
common->Printf( "USAGE: envToSky <basename>\n" ); common->Printf( "USAGE: envToSky <basename>\n" );
return; return;
} }
@ -1938,9 +1978,11 @@ to env textures (of the type px, py, pz, nx, ny, nz)
================== ==================
*/ */
void R_TransformSkyboxToEnv_f ( const idCmdArgs& args ){ void R_TransformSkyboxToEnv_f( const idCmdArgs& args )
{
if( args.Argc() != 2 ) { if( args.Argc() != 2 )
{
common->Printf( "USAGE: skyToEnv <basename>\n" ); common->Printf( "USAGE: skyToEnv <basename>\n" );
return; return;
} }