Ejemplo n.º 1
0
int main( int argc, const char** argv )
{
	ArgParse ap;
	RtFilterFunc filterfunc;
	float bake;

	ap.usageHeader( ArgParse::apstring( "Usage: " ) + argv[ 0 ] + " [options] infile outfile" );
	ap.argFlag( "help", "\aPrint this help and exit", &g_help );
	ap.alias( "help" , "h" );
	ap.argFlag( "version", "\aPrint version information and exit", &g_version );
	ap.argInt( "verbose", "=integer\aSet log output level\n"
		"\a0 = errors\n"
		"\a1 = warnings (default)\n"
		"\a2 = information\n"
		"\a3 = debug", &g_cl_verbose );
	ap.alias( "verbose" , "v" );
	ap.argString( "compression", "=string\a[none|lzw|packbits|deflate] (default: %default)", &g_compress );
	ap.argFlag( "envcube", " px nx py ny pz nz\aproduce a cubeface environment map from 6 images.", &g_envcube );
	ap.argFlag( "envlatl", "\aproduce a latlong environment map from an image file.", &g_envlatl );
	ap.argFlag( "shadow", "\aproduce a shadow map from a z file.", &g_shadow );
	ap.argString( "swrap", "=string\as wrap [black|periodic|clamp] (default: %default)", &g_swrap );
	ap.argString( "smode", "=string\a(equivalent to swrap for BMRT compatibility)", &g_swrap );
	ap.argString( "twrap", "=string\at wrap [black|periodic|clamp] (default: %default)", &g_twrap );
	ap.argString( "tmode", "=string\a(equivalent to twrap for BMRT compatibility)", &g_swrap );
	ap.argString( "wrap", "=string\awrap s&t [black|periodic|clamp]", &g_wrap );
	ap.argString( "mode", "=string\as (equivalent to wrap for BMRT compatibility)", &g_wrap );
	ap.argString( "filter", "=string\a[box|bessel|catmull-rom|disk|gaussian|sinc|triangle|mitchell] (default: %default)", &g_filter );
	ap.argFloat( "fov(envcube)", "=float\a[>=0.0f] (default: %default)", &g_fov );
	ap.argFloat( "swidth", "=float\as width [>0.0f] (default: %default)", &g_swidth );
	ap.alias( "swidth", "sfilterwidth" );
	ap.argFloat( "twidth", "=float\at width [>0.0f] (default: %default)", &g_twidth );
	ap.alias( "twidth", "tfilterwidth" );
	ap.argFloat( "width", "=float\awidth [>0.0f] set both swidth and twidth (default: %default)", &g_width );
	ap.alias( "width", "filterwidth" );
	ap.argFloat( "quality", "=float\a[>=1.0f && <= 100.0f] (default: %default)", &g_quality );
	ap.argFloat( "bake", "=float\a[>=2.0f && <= 2048.0f] (default: %default)", &g_bake );
	ap.argString( "resize", "=string\a[up|down|round|up-|down-|round-] (default: %default)\n\aNot used, for BMRT compatibility only!", &g_resize );


	if ( argc > 1 && !ap.parse( argc - 1, argv + 1 ) )
	{
		Aqsis::log() << ap.errmsg() << std::endl << ap.usagemsg();
		exit( 1 );
	}

	if ( g_version )
	{
		version( std::cout );
		exit( 0 );
	}

	if ( g_help || ap.leftovers().size() <= 1 )
	{
		std::cout << ap.usagemsg();
		exit( 0 );
	}

	if ( g_envcube && g_shadow )
	{
		std::cout << "Specify only one of envcube or shadow" << std::endl;
		exit( 1 );
	}


	/* find the pixel's filter function */
	filterfunc = RiBoxFilter;
	if ( g_filter == "box" )
		filterfunc = RiBoxFilter;
	else if ( g_filter == "mitchell" )
		filterfunc = RiMitchellFilter;
	else if ( g_filter == "sinc" )
		filterfunc = RiSincFilter;
	else if ( g_filter == "catmull-rom" )
		filterfunc = RiCatmullRomFilter;
	else if ( g_filter == "disk" )
		filterfunc = RiDiskFilter;
	else if ( g_filter == "bessel" )
		filterfunc = RiBesselFilter;
	else if ( g_filter == "triangle" )
		filterfunc = RiTriangleFilter;
	else if ( g_filter == "gaussian" )
		filterfunc = RiGaussianFilter;



	/* protect the s,t width */
	if ( g_swidth < 1.0 )
	{
		Aqsis::log() << "g_swidth is smaller than 1.0." << " 1.0 will be used instead." << std::endl;
		g_swidth = 1.0;
	}
	if ( g_twidth < 1.0 )
	{
		Aqsis::log() << "g_twidth is smaller than 1.0." << " 1.0 will be used instead." << std::endl;
		g_twidth = 1.0;
	}

	/* protect the s,t wrap mode */
	if ( !( ( g_swrap == "black" ) || ( g_swrap == "periodic" ) || ( g_swrap == "clamp" ) ) )
	{
		Aqsis::log() << "Unknown s wrap mode: " << g_swrap << ". black will be used instead." << std::endl;
		g_swrap = "black";
	}
	if ( !( ( g_twrap == "black" ) || ( g_twrap == "periodic" ) || ( g_twrap == "clamp" ) ) )
	{
		Aqsis::log() << "Unknown t wrap mode: " << g_twrap << ". black will be used instead." << std::endl;
		g_twrap = "black";
	}
	if ( !( ( g_wrap == "" ) || ( g_wrap == "black" ) || ( g_wrap == "periodic" ) || ( g_wrap == "clamp" ) ) )
	{
		Aqsis::log() << "Unknown wrap mode: " << g_wrap << ". black will be used instead." << std::endl;
		g_wrap = "black";
	}

	/* If wrap is specified, it overrides both s and t */
	if( g_wrap != "" )
	{
		g_twrap = g_wrap;
		g_swrap = g_wrap;
	}

	/* Need to set both st width ? */
	if ( g_width > 0.0 )
	{
		g_twidth = g_swidth = g_width;
	}

	/* protect the compression mode */
	if ( !( ( g_compress == "deflate" ) ||
	        ( g_compress == "lzw" ) ||
	        ( g_compress == "none" ) ||
	        ( g_compress == "packbits" )
	      )
	   )
	{
		Aqsis::log() << "Unknown compression mode: " << g_compress << ". none." << std::endl;
		g_compress = "none";
	}

	/* protect the quality mode */
	if ( g_quality < 1.0f )
		g_quality = 1.0;
	if ( g_quality > 100.0f )
		g_quality = 100.0;

	/* protect the bake mode */
	if ( g_bake < 2.0f )
		g_bake = 2.0;
	if ( g_bake > 2048.0f )
		g_bake = 2048.0;

	char *compression = ( char * ) g_compress.c_str();
	float quality = ( float ) g_quality;


	std::auto_ptr<std::streambuf> show_level( new Aqsis::show_level_buf(Aqsis::log()) );
	Aqsis::log_level_t level = Aqsis::ERROR;
	if( g_cl_verbose > 0 )
		level = Aqsis::WARNING;
	if( g_cl_verbose > 1 )
		level = Aqsis::INFO;
	if( g_cl_verbose > 2 )
		level = Aqsis::DEBUG;
	std::auto_ptr<std::streambuf> filter_level( new Aqsis::filter_by_level_buf(level, Aqsis::log()) );

	RiBegin(RI_NULL);

	if ( g_envcube )
	{
		if ( ap.leftovers().size() != 7 )
		{
			Aqsis::log() << "Need 6 images for cubic environment map" << std::endl;
			return ( -1 );
		}

		printf( "CubeFace Environment %s %s %s %s %s %s ----> %s \n\t\"fov\"= %4.1f\n\t\"filter\"= %s \n\t\"swidth\"= %4.1f\n\t\"twidth\"= %4.1f\n\t\"compression\" = %s\n",
		        const_cast<char*>(ap.leftovers() [ 0 ].c_str()),
		        const_cast<char*>(ap.leftovers() [ 1 ].c_str()),
		        const_cast<char*>(ap.leftovers() [ 2 ].c_str()),
		        const_cast<char*>(ap.leftovers() [ 3 ].c_str()),
		        const_cast<char*>(ap.leftovers() [ 4 ].c_str()),
		        const_cast<char*>(ap.leftovers() [ 5 ].c_str()),
		        const_cast<char*>(ap.leftovers() [ 6 ].c_str()),
		        g_fov,
		        g_filter.c_str(),
		        g_swidth,
		        g_twidth,
		        ( char* ) g_compress.c_str()
		      );

		RiMakeCubeFaceEnvironment(
		    const_cast<char*>(ap.leftovers() [ 0 ].c_str()),
		    const_cast<char*>(ap.leftovers() [ 1 ].c_str()),
		    const_cast<char*>(ap.leftovers() [ 2 ].c_str()),
		    const_cast<char*>(ap.leftovers() [ 3 ].c_str()),
		    const_cast<char*>(ap.leftovers() [ 4 ].c_str()),
		    const_cast<char*>(ap.leftovers() [ 5 ].c_str()),
		    const_cast<char*>(ap.leftovers() [ 6 ].c_str()),
		    g_fov,
		    filterfunc,
		    ( float ) g_swidth,
		    ( float ) g_twidth,
		    "compression",
		    &compression,
		    "quality",
		    &quality,
		    RI_NULL );
	}
	else if ( g_shadow )
	{
		printf( "Shadow %s ----> %s \n\t\"compression\" = %s\n",
		        ( char* ) ap.leftovers() [ 0 ].c_str(),
		        ( char* ) ap.leftovers() [ 1 ].c_str(),
		        ( char* ) g_compress.c_str() );



		RiMakeShadow( ( char* ) ap.leftovers() [ 0 ].c_str(), ( char* ) ap.leftovers() [ 1 ].c_str(), ( float ) g_twidth, "compression", &compression, "quality", &quality, RI_NULL );
	}
	else if ( g_envlatl )
	{
		printf( "LatLong Environment %s ----> %s \n\t\"compression\" = %s \n",
		        ( char* ) ap.leftovers() [ 0 ].c_str(),
		        ( char* ) ap.leftovers() [ 1 ].c_str(),
		        ( char* ) g_compress.c_str() );

		RiMakeLatLongEnvironment( ( char* ) ap.leftovers() [ 0 ].c_str(), ( char* ) ap.leftovers() [ 1 ].c_str(), filterfunc,
		                          ( float ) g_swidth, ( float ) g_twidth, "compression", &compression, "quality", &quality, RI_NULL );
	}
	else
	{
		printf( "Texture %s ----> %s \n\t\"swrap\"= %s \n\t\"twrap\"= %s \n\t\"filter\"= %s \n\t\"swidth\"= %4.1f\n\t\"twidth\"= %4.1f\n\t\"compression\" = %s\n",
		        ( char* ) ap.leftovers() [ 0 ].c_str(),
		        ( char* ) ap.leftovers() [ 1 ].c_str(),
		        ( char* ) g_swrap.c_str(),
		        ( char* ) g_twrap.c_str(),
		        ( char* ) g_filter.c_str(),
		        g_swidth,
		        g_twidth,
		        compression
		      );

 		bake = g_bake;

		RiMakeTexture( ( char* ) ap.leftovers() [ 0 ].c_str(), ( char* ) ap.leftovers() [ 1 ].c_str(),
		               ( char* ) g_swrap.c_str(), ( char* ) g_twrap.c_str(), filterfunc,
		               ( float ) g_swidth, ( float ) g_twidth, "compression", &compression, "quality", &quality, "float bake", &bake, RI_NULL );
	}

	RiEnd();

	return ( 0 );
}
Ejemplo n.º 2
0
int main( int argc, const char** argv )
{
	std::signal(SIGINT, aqsisSignalHandler);
	std::signal(SIGABRT, aqsisSignalHandler);
	RtInt returnCode = 0;

	StartMemoryDebugging();
	{
		ArgParse ap;
		ap.usageHeader( ArgParse::apstring( "Aqsis command line renderer\nUsage: " ) + argv[ 0 ] + " [options] [RIB file...]" );
		ap.argFlag( "help", "\aPrint this help and exit", &g_cl_help );
		ap.alias( "help" , "h" );
		ap.argFlag( "version", "\aPrint version information and exit", &g_cl_version );
		ap.argFlag( "pause", "\aWait for a keypress on completion", &g_cl_pause );
		ap.argFlag( "progress", "\aPrint progress information", &g_cl_progress );
		ap.argFlag( "Progress", "\aPrint PRMan-compatible progress information (ignores -progressformat)", &g_cl_Progress );
		ap.argString( "progressformat", "=string\aprintf-style format string for -progress", &g_cl_strprogress );
		ap.argInt( "endofframe", "=integer\aEquivalent to \"endofframe\" RIB option", &g_cl_endofframe );
		ap.argInt( "verbose", "=integer\aSet log output level\n"
		           "\a0 = errors\n"
		           "\a1 = warnings (default)\n"
		           "\a2 = information\n"
		           "\a3 = debug", &g_cl_verbose );
		ap.alias( "verbose", "v" );
		ap.argFlag( "echoapi", "\aEcho all RI API calls to the log output (experimental)", &g_cl_echoapi);

		ap.argInt( "priority", "=integer\aControl the priority class of aqsis.\n"
			"\a0 = idle\n"
			"\a1 = normal\n"
			"\a2 = high\n"
			"\a3 = RT", &g_cl_priority);
		ap.alias( "priority", "z");
		
		ap.argString( "type", "=string\aSpecify a display device type to use", &g_cl_type );
		ap.argString( "addtype", "=string\aSpecify a display device type to add", &g_cl_addtype );
		ap.argString( "mode", "=string\aSpecify a display device mode to use", &g_cl_mode );
		ap.argFlag( "fb", "\aSame as --type=\"framebuffer\" --mode=\"rgb\"", &g_cl_fb );
		ap.alias( "fb", "d" );
		ap.argFloats( "crop", " x1 x2 y1 y2\aSpecify a crop window, values are in screen space.", &g_cl_cropWindow, ArgParse::SEP_ARGV, 4);
		ap.argFlag( "nocolor", "\aDisable colored output", &g_cl_no_color );
		ap.argFlag( "beep", "\aBeep on completion of all ribs", &g_cl_beep );
		ap.alias( "nocolor", "nc" );
		ap.argInts( "res", " x y\aSpecify the resolution of the render.", &g_cl_res, ArgParse::SEP_ARGV, 2);
		ap.argStrings( "option", "=string\aA valid RIB Option string, can be specified multiple times.", &g_cl_options);
#		ifdef AQSIS_SYSTEM_POSIX
		ap.argFlag( "syslog", "\aLog messages to syslog", &g_cl_syslog );
#		endif // AQSIS_SYSTEM_POSIX
#		if ENABLE_MPDUMP
		ap.argFlag( "mpdump", "\aOutput MP list to a custom 'dump' file", &g_cl_mpdump );
#		endif // ENABLE_MPDUMP

		ap.argString( "shaders", "=string\aOverride the default shader searchpath(s)", &g_cl_shader_path );
		ap.argString( "archives", "=string\aOverride the default archive searchpath(s)", &g_cl_archive_path );
		ap.argString( "textures", "=string\aOverride the default texture searchpath(s)", &g_cl_texture_path );
		ap.argString( "displays", "=string\aOverride the default display searchpath(s)", &g_cl_display_path );
		ap.argString( "procedurals", "=string\aOverride the default procedural searchpath(s)", &g_cl_procedural_path );
		ap.allowUnrecognizedOptions();

		if ( argc > 1 && !ap.parse( argc - 1, argv + 1 ) )
		{
			Aqsis::log() << ap.errmsg() << std::endl << ap.usagemsg();
			return( 1 );
		}

		// Check that the number of arguments to crop are valid if specified.
		if ( g_cl_cropWindow.size() > 0 && g_cl_cropWindow.size() != 4 )
		{
			Aqsis::log() << Aqsis::error << "Invalid number of arguments to -crop, expected 4, got " << g_cl_cropWindow.size() << std::endl;
			g_cl_help = true;
		}

		if ( g_cl_help )
		{
			std::cout << ap.usagemsg();
			return( 0 );
		}

		if ( g_cl_version )
		{
			std::cout << "aqsis version " << AQSIS_VERSION_STR_FULL
#			ifdef _DEBUG
			<< " (debug build)"
#			endif
			<< "\n"
			<< "compiled " << __DATE__ << " " << __TIME__ << "\n";
			return( 0 );
		}

#		ifdef	AQSIS_SYSTEM_WIN32
		std::auto_ptr<std::streambuf> ansi( new Aqsis::ansi_buf(Aqsis::log()) );
#		endif

		std::auto_ptr<std::streambuf> reset_level( new Aqsis::reset_level_buf(Aqsis::log()) );
		std::auto_ptr<std::streambuf> show_timestamps( new Aqsis::timestamp_buf(Aqsis::log()) );
		std::auto_ptr<std::streambuf> fold_duplicates( new Aqsis::fold_duplicates_buf(Aqsis::log()) );
		std::auto_ptr<std::streambuf> color_level;
		if(!g_cl_no_color)
		{
			std::auto_ptr<std::streambuf> temp_color_level( new Aqsis::color_level_buf(Aqsis::log()) );
			color_level = temp_color_level;
		}
		std::auto_ptr<std::streambuf> show_level( new Aqsis::show_level_buf(Aqsis::log()) );
		Aqsis::log_level_t level = Aqsis::ERROR;
		if( g_cl_verbose > 0 )
			level = Aqsis::WARNING;
		if( g_cl_verbose > 1 )
			level = Aqsis::INFO;
		if( g_cl_verbose > 2 )
			level = Aqsis::DEBUG;
		std::auto_ptr<std::streambuf> filter_level( new Aqsis::filter_by_level_buf(level, Aqsis::log()) );
#		ifdef AQSIS_SYSTEM_POSIX
		if( g_cl_syslog )
			std::auto_ptr<std::streambuf> use_syslog( new Aqsis::syslog_buf(Aqsis::log()) );
#		endif // AQSIS_SYSTEM_POSIX

		if (g_cl_priority != 1)
		{
			// Set the priority on the main thread
			setPriority(g_cl_priority);
		}

		RiBegin(RI_NULL);
		setupOptions();
		try
		{
			if ( ap.leftovers().size() == 0 )
			{
				// If no files specified, take input from stdin.
				//
				// TODO: We'd like to turn off stdio synchronisation to allow fast
				// buffering... unfortunately this causes very odd problems with
				// the aqsis logging facility as of svn r2804
				//
				//std::ios_base::sync_with_stdio(false);
				Aqsis::QGetRenderContextI()->parseRibStream(std::cin, "stdin");
			}
			else
			{
				for(ArgParse::apstringvec::const_iterator fileName = ap.leftovers().begin();
						fileName != ap.leftovers().end(); fileName++)
				{
					std::ifstream inFile(fileName->c_str());
					if(inFile)
					{
						Aqsis::QGetRenderContextI()->parseRibStream(inFile, *fileName);
						returnCode = RiLastError;
					}
					else
					{
						Aqsis::log() << Aqsis::error
							<< "Cannot open file \"" << *fileName << "\"\n";
						returnCode = RIE_NOFILE;
					}
				}
			}
		}
		catch(const std::exception& e)
		{
			Aqsis::log() << Aqsis::error << e.what() << std::endl;
			returnCode = RIE_BUG;
		}
		catch(...)
		{
			Aqsis::log() << Aqsis::error
				<< "unknown exception has been encountered\n";
			returnCode = RIE_BUG;
		}
		RiEnd();
	}

	StopMemoryDebugging();

	if(g_cl_beep)
		std::cout << "\a" << std::ends;

	if(g_cl_pause)
	{
		std::cout << "Press any key..." << std::ends;
		std::cin.ignore(std::cin.rdbuf()->in_avail() + 1);
	}

	return returnCode;
}
Ejemplo n.º 3
0
int main( int argc, const char** argv )
{

#ifdef	AQSIS_SYSTEM_WIN32
	char acPath[256];
	char rootPath[256];
	if( GetModuleFileName( NULL, acPath, 256 ) != 0)
	{
		// guaranteed file name of at least one character after path
		*( strrchr( acPath, '\\' ) + 1 ) = '\0';
		std::string	 stracPath(acPath);
		stracPath.append("..\\");
		_fullpath(rootPath,&stracPath[0],256);
	}
	g_shader_path = rootPath;
	g_shader_path.append( "shaders" );
#elif defined(AQSIS_SYSTEM_MACOSX)
#else

	g_shader_path = AQSIS_XSTR(DEFAULT_SHADER_PATH);
#endif

	/*Aqsis::QGetRenderContextI();*/
	ArgParse ap;
	ap.usageHeader( ArgParse::apstring( "Usage: " ) + argv[ 0 ] + " <shadername>" );
	ap.argFlag( "help", "\aPrint this help and exit", &g_cl_help );
	ap.alias( "help" , "h" );
	ap.argFlag( "version", "\aPrint version information and exit", &g_cl_version );
	ap.argString( "shaders", "=string\aOverride the default shader searchpath(s) [" + g_shader_path + "]", &g_cl_shader_path );

	if ( argc > 1 && !ap.parse( argc - 1, argv + 1 ) )
	{
		Aqsis::log() << ap.errmsg() << std::endl << ap.usagemsg();
		exit( 1 );
	}

	if ( g_cl_help )
	{
		std::cout << ap.usagemsg();
		exit( 0 );
	}

	if ( g_cl_version )
	{
		std::cout << "aqsltell version " << AQSIS_VERSION_STR_FULL << std::endl << "compiled " << __DATE__ << " " << __TIME__ << std::endl;
		exit( 0 );
	}

	// Apply environment-variable overrides to default paths ...
	if(getenv("AQSIS_SHADER_PATH"))
		g_shader_path = getenv("AQSIS_SHADER_PATH");

	// Apply command-line overrides to default paths ...
	if(!g_cl_shader_path.empty())
		g_shader_path = g_cl_shader_path;

	// Any leftovers are presumed to be shader names.
	if ( ap.leftovers().size() == 0 )     // If no files specified, take input from stdin.
	{
		Aqsis::log() << ap.errmsg() << std::endl << ap.usagemsg();
		exit( 1 );
	}
	else
	{
		for ( ArgParse::apstringvec::const_iterator e = ap.leftovers().begin(); e != ap.leftovers().end(); e++ )
		{
			SLX_SetPath( const_cast<char*>( g_shader_path.c_str() ) );
			SLX_SetDSOPath( const_cast<char*>( g_shader_path.c_str() ) );
			Slo_SetShader( ( char* ) e->c_str() );

			if ( SLX_SetShader( ( char* ) e->c_str() ) == 0 )
			{
				// SLX_SetShader successful
				int	nArgs;
				int i;
				SLX_VISSYMDEF * symPtr;

				std::cout << SLX_TypetoStr( SLX_GetType() ) << " \"" << Slo_GetName() << "\"" << std::endl;
				nArgs = SLX_GetNArgs();

				for ( i = 0; i < nArgs; i++ )
				{
					symPtr = SLX_GetArgById( i );
					if ( symPtr != NULL )
					{
						TqInt arrayLen = 1;
						if ( symPtr->svd_arraylen != 0 )
							arrayLen = symPtr->svd_arraylen;

						std::cout << "    \"" << symPtr->svd_name << "\" \"parameter " <<
						SLX_DetailtoStr( symPtr->svd_detail ) << " " <<
						SLX_TypetoStr( symPtr->svd_type );

						if ( symPtr->svd_arraylen != 0 )
							std::cout << "[" << arrayLen << "]";

						std::cout << "\"" << std::endl;

						TqInt arrayIndex;
						for ( arrayIndex = 0; arrayIndex < arrayLen; arrayIndex++ )
						{
							std::cout << "\t\tDefault value: ";

							if ( symPtr->svd_spacename != NULL )
							{
								if ( ( symPtr->svd_type == SLX_TYPE_POINT ) ||
								        ( symPtr->svd_type == SLX_TYPE_NORMAL ) ||
								        ( symPtr->svd_type == SLX_TYPE_VECTOR ) ||
								        ( symPtr->svd_type == SLX_TYPE_MATRIX ) ||
								        ( symPtr->svd_type == SLX_TYPE_COLOR ) )
									std::cout << "\"" << symPtr->svd_spacename << "\" ";
							}

							if ( symPtr->svd_default.stringval != NULL )
							{
								switch ( symPtr->svd_type )
								{
										case SLX_TYPE_UNKNOWN:
										std::cout << "unknown" << std::endl;
										break;
										case SLX_TYPE_POINT:
										case SLX_TYPE_NORMAL:
										case SLX_TYPE_VECTOR:
										std::cout << "[" << symPtr->svd_default.pointval[ arrayIndex ].xval << " " <<
										symPtr->svd_default.pointval[ arrayIndex ].yval << " " <<
										symPtr->svd_default.pointval[ arrayIndex ].zval <<
										"]" << std::endl;
										break;
										case SLX_TYPE_COLOR:
										std::cout << "[" << symPtr->svd_default.pointval[ arrayIndex ].xval << " " <<
										symPtr->svd_default.pointval[ arrayIndex ].yval << " " <<
										symPtr->svd_default.pointval[ arrayIndex ].zval <<
										"]" << std::endl;
										break;
										case SLX_TYPE_SCALAR:
										std::cout << symPtr->svd_default.scalarval[ arrayIndex ] << std::endl;
										break;
										case SLX_TYPE_STRING:
										std::cout << "\"" << symPtr->svd_default.stringval[ arrayIndex ] << "\"" << std::endl;
										break;
										case SLX_TYPE_MATRIX:
										std::cout << "[" <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[0][0] << " " <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[0][1] << " " <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[0][2] << " " <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[0][2] << " " <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[1][0] << " " <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[1][1] << " " <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[1][2] << " " <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[1][2] << " " <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[2][0] << " " <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[2][1] << " " <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[2][2] << " " <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[2][3] << " " <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[3][0] << " " <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[3][1] << " " <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[3][2] << " " <<
										symPtr->svd_default.matrixval[ arrayIndex ].val[3][3] <<
										"]" << std::endl;
										break;
										default:
										std::cout << "unknown" << std::endl;
										break;
								}
							}
						}
					}
					else
					{
						printf( "ERROR - null pointer to value\n" );
					}
					//std::cout << std::endl;
				}

				SLX_EndShader();
			}
			else
			{
				printf("ERROR - could not read shader file\n");
			}
		}
	}

	return ( 0 );
}
Ejemplo n.º 4
0
/** Process the sl file from stdin and produce an slx bytestream.
 */
int main( int argc, const char** argv )
{
	ArgParse ap;
	boost::scoped_ptr<IqCodeGen> codeGenerator;
	bool error = false; ///! Couldn't compile shader

	ap.usageHeader( ArgParse::apstring( "Usage: " ) + argv[ 0 ] + " [options] <filename>" );
	ap.argString( "o", " %s \aspecify output filename", &g_stroutname );
	ap.argStrings( "i", "%s \aSet path for #include files.", &g_includes );
	ap.argStrings( "I", "%s \aSet path for #include files.", &g_includes );
	ap.argStrings( "D", "Sym[=value] \adefine symbol <string> to have value <value> (default: 1).", &g_defines );
	ap.argStrings( "U", "Sym \aUndefine an initial symbol.", &g_undefines );
	ap.argString( "backend", " %s \aCompiler backend (default %default).  Possibilities include \"slx\" or \"dot\":\a"
			      "slx - produce a compiled shader (in the aqsis shader VM stack language)\a"
				  "dot - make a graphviz visualization of the parse tree (useful for debugging only).", &g_backendName );
	ap.argFlag( "help", "\aPrint this help and exit", &g_help );
	ap.alias("help", "h");
	ap.argFlag( "version", "\aPrint version information and exit", &g_version );
	ap.argFlag( "nocolor", "\aDisable colored output", &g_cl_no_color );
	ap.alias( "nocolor" , "nc" );
	ap.argFlag( "d", "\adump sl data", &g_dumpsl );
	ap.argInt( "verbose", "=integer\aSet log output level\n"
			   "\a0 = errors\n"
			   "\a1 = warnings (default)\n"
			   "\a2 = information\n"
			   "\a3 = debug", &g_cl_verbose );
	ap.alias( "verbose", "v" );

	if ( argc > 1 && !ap.parse( argc - 1, argv + 1 ) )
	{
		Aqsis::log() << ap.errmsg() << std::endl << ap.usagemsg();
		exit( 1 );
	}

	if ( g_version )
	{
		version( std::cout );
		exit( 0 );
	}

	if ( g_help )
	{
		std::cout << ap.usagemsg();
		exit( 0 );
	}

#ifdef	AQSIS_SYSTEM_WIN32
	std::auto_ptr<std::streambuf> ansi( new Aqsis::ansi_buf(Aqsis::log()) );
#endif

	std::auto_ptr<std::streambuf> reset_level( new Aqsis::reset_level_buf(Aqsis::log()) );
	std::auto_ptr<std::streambuf> show_timestamps( new Aqsis::timestamp_buf(Aqsis::log()) );
	std::auto_ptr<std::streambuf> fold_duplicates( new Aqsis::fold_duplicates_buf(Aqsis::log()) );
	std::auto_ptr<std::streambuf> color_level;
	if(!g_cl_no_color)
	{
		std::auto_ptr<std::streambuf> temp_color_level( new Aqsis::color_level_buf(Aqsis::log()) );
		color_level = temp_color_level;
	}
	std::auto_ptr<std::streambuf> show_level( new Aqsis::show_level_buf(Aqsis::log()) );
	Aqsis::log_level_t level = Aqsis::ERROR;
	if( g_cl_verbose > 0 )
		level = Aqsis::WARNING;
	if( g_cl_verbose > 1 )
		level = Aqsis::INFO;
	if( g_cl_verbose > 2 )
		level = Aqsis::DEBUG;
	std::auto_ptr<std::streambuf> filter_level( new Aqsis::filter_by_level_buf(level, Aqsis::log()) );
#ifdef	AQSIS_SYSTEM_POSIX

	if( g_cl_syslog )
		std::auto_ptr<std::streambuf> use_syslog( new Aqsis::syslog_buf(Aqsis::log()) );
#endif	// AQSIS_SYSTEM_POSIX

	if ( ap.leftovers().size() == 0 )
	{
		std::cout << ap.usagemsg();
		exit( 0 );
	}
	else
	{
		for ( ArgParse::apstringvec::const_iterator e = ap.leftovers().begin(); e != ap.leftovers().end(); e++ )
		{
			//Expand filenames
			std::vector<std::string> files = Aqsis::cliGlob(*e);
			std::vector<std::string>::iterator it;
			for(it = files.begin(); it != files.end(); ++it){ 
				ResetParser();
				// Create a code generator for the requested backend.
				if(g_backendName == "slx")
					codeGenerator.reset(new CqCodeGenVM());
				else if(g_backendName == "dot")
					codeGenerator.reset(new CqCodeGenGraphviz());
				else
				{
					std::cout << "Unknown backend type: \"" << g_backendName << "\", assuming slx.";
					codeGenerator.reset(new CqCodeGenVM());
				}
				// current file position is saved for exception handling
				boost::wave::util::file_position_type current_position;

				try
				{
					//  Open and read in the specified input file.
					std::ifstream instream(it->c_str());
					std::string instring;
	
					if (!instream.is_open()) 
					{
						std::cerr << "Could not open input file: " << *it << std::endl;
						continue;
					}
					instream.unsetf(std::ios::skipws);
					instring = std::string(std::istreambuf_iterator<char>(instream.rdbuf()),
					    std::istreambuf_iterator<char>());
	
					typedef boost::wave::cpplexer::lex_token<> token_type;
					typedef boost::wave::cpplexer::lex_iterator<token_type> lex_iterator_type;
					typedef boost::wave::context<std::string::iterator, lex_iterator_type>
					    context_type;
					context_type ctx (instring.begin(), instring.end(), it->c_str());

					// Append the -i arguments passed in to forward them to the preprocessor.
					for ( ArgParse::apstringvec::const_iterator include = g_includes.begin(); include != g_includes.end(); include++ )
					{
						ctx.add_sysinclude_path( include->c_str() );
						ctx.add_include_path( include->c_str() );
					}
  
					// Setup the default defines.
					ctx.add_macro_definition( "AQSIS" );
					ctx.add_macro_definition( "PI=3.141592654" );
  
					// Append the -d arguments passed in to forward them to the preprocessor.
					for ( ArgParse::apstringvec::const_iterator define = g_defines.begin(); define != g_defines.end(); define++ )
					{
						ctx.add_macro_definition( define->c_str() );
					}
  
					// Append the -u arguments passed in to forward them to the preprocessor.
					for ( ArgParse::apstringvec::const_iterator undefine = g_undefines.begin(); undefine != g_undefines.end(); undefine++ )
					{
						ctx.remove_macro_definition( undefine->c_str() );
					}
  
					// analyze the input file
					context_type::iterator_type first = ctx.begin();
					context_type::iterator_type last = ctx.end();

					std::stringstream preprocessed(std::stringstream::in | std::stringstream::out);
					std::ofstream dumpfile;
					if( g_dumpsl )
					{
						std::string dumpfname(*it);
						dumpfname.append(".pp");
						dumpfile.open(dumpfname.c_str());
					};

					while (first != last) 
					{
						current_position = (*first).get_position();
						preprocessed << (*first).get_value();
						dumpfile << (*first).get_value();

						try
						{
							++first	;
						}
						catch (boost::wave::preprocess_exception &e) 
  						{
							Aqsis::log() 
							<< e.file_name() << "(" << e.line_no() << "): "
							<< e.description() << std::endl;
							if (e.get_errorcode() == ::boost::wave::preprocess_exception::last_line_not_terminated )
							{
								preprocessed << std::endl;
								dumpfile << std::endl;
								break;
							};
  						}
						catch (...) 
						{
							throw &e;
						}

					};
  
					if( dumpfile.is_open() )
						dumpfile.close();
  
					if ( Parse( preprocessed, e->c_str(), Aqsis::log() ) )
						codeGenerator->OutputTree( GetParseTree(), g_stroutname );
					else
						error = true;
				}
				catch (boost::wave::cpp_exception &e) 
				{
					// some preprocessing error
					Aqsis::log() 
					<< e.file_name() << "(" << e.line_no() << "): "
					<< e.description() << std::endl;
					continue;
				}
				catch (std::exception &e)
				{
					// use last recognized token to retrieve the error position
					Aqsis::log() << current_position.get_file()
				        << "(" << current_position.get_line() << "): "
				        << "exception caught: " << e.what()
				        << std::endl;
					continue;
				}
				catch (...) {
					// use last recognized token to retrieve the error position
					Aqsis::log() << current_position.get_file()
					<< "(" << current_position.get_line() << "): "
					<< "unexpected exception caught." << std::endl;
					continue;
				}
			}
		};
	}

	return error;
}
Ejemplo n.º 5
0
int main(int argc, const char** argv)
{
	ArgParse::apflag showhelp = false;
	ArgParse::apint myint = 0;

	ArgParse ap;
	ap.allowOneCharOptionsToBeCombined();
	ap.usageHeader(ArgParse::apstring("Usage: ") + argv[0] + " [options]");
	ap.argFlag("help", "\aprint this help, then exit", &showhelp);
	ap.argInt("integer", "=value\aa random integer you can give for no reason",
	          &myint);
	ap.alias("help", "h");
	ap.alias("integer", "i");
	if (!ap.parse(argc-1, argv+1))
	{
		Aqsis::log() << ap.errmsg() << std::endl << ap.usagemsg();
		return 1;
	}

	if (ap.leftovers().size() > 0)
	{
		Aqsis::log() << "Extra crud \"" << ap.leftovers()[0] << "\" on command line";
		Aqsis::log() << std::endl << ap.usagemsg();
		return 1;
	}

	if (myint != 0)
	{
		cout << "Your favorite integer is " << myint << endl;
	}

	if (showhelp)
	{
		cout << ap.usagemsg();
		return 0;
	}

	int bad = 0;

	cout << "Testing flags and integers... ";
	myint = 3;
	showhelp = false;
	int ok = 0;
	const char* av[100];

	if (ap.parse(0, av) && !showhelp && myint == 3 && ap.leftovers().size() == 0)
		ok++;

	av[0] = "-h";
	if (ap.parse(1, av) && showhelp && myint == 3 && ap.leftovers().size() == 0)
		ok++;

	showhelp = false;
	av[0] = "--help";
	if (ap.parse(1, av) && showhelp && myint == 3 && ap.leftovers().size() == 0)
		ok++;

	showhelp = false;
	av[0] = "--integer";
	av[1] = "5";
	if (ap.parse(2, av) && !showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	myint = 3;
	av[0] = "-i";
	if (ap.parse(2, av) && !showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	myint = 3;
	av[2] = "--help";
	if (ap.parse(3, av) && showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	av[0] = "-h";
	av[1] = "-i";
	av[2] = "5";
	myint = 3;
	showhelp = false;
	if (ap.parse(3, av) && showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	av[0] = "-hi";
	av[1] = "5";
	myint = 3;
	showhelp = false;
	if (ap.parse(2, av) && showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	av[0] = "-hi=5";
	myint = 3;
	showhelp = false;
	if (ap.parse(1, av) && showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	av[0] = "-help";
	if (!ap.parse(1, av) &&
	        ap.errmsg() == "-help: 'e' is an unrecognized option")
		ok++;

	av[0] = "--integer=5";
	myint = 3;
	showhelp = false;
	if (ap.parse(1, av) && !showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	av[0] = "--integer:5";
	myint = 3;
	if (ap.parse(1, av) && !showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	av[0] = "-ih";
	av[1] = "5";
	if (!ap.parse(2, av) &&
	        ap.errmsg() == "-ih: 'i' requires an argument")
		ok++;

	av[0] = "--help=5";
	if (!ap.parse(1, av) &&
	        ap.errmsg() == "--help=5: doesn't take an argument")
		ok++;

	av[0] = "--nohelp";
	showhelp = true;
	myint = 3;
	if (ap.parse(1, av) && !showhelp && myint == 3 && ap.leftovers().size() == 0)
		ok++;

	av[1] = "--help";
	if (!ap.parse(2, av) &&
	        ap.errmsg() == "--help: negated flag used with non-negated flag")
		ok++;

	if (ok == 16)
	{
		cout << "PASS" << endl;
	}
	else
	{
		cout << "FAIL" << endl;
		bad++;
	}

	ok = 0;
	cout << "Testing strings and floats... ";

	ArgParse::apfloat tex;
	ArgParse::apfloat metafont;
	ArgParse::apstring kpathsea;
	ArgParse t1;
	t1.argFloat("tex", "\aversion of TeX", &tex);
	t1.argFloat("metafont", "\aversion of Metafont", &metafont);
	t1.argString("kpathsea", "\aversion of Kpathsea", &kpathsea);

	av[0] = "-tex";
	av[1] = "3.14159";
	av[2] = "--metafont=2.7182";
	av[3] = "--kpathsea";
	av[4] = "3.3.1";
	if (t1.parse(5, av) && t1.leftovers().size() == 0 &&
	        tex == 3.14159 && metafont == 2.7182 && kpathsea == "3.3.1")
		ok++;

	av[1] = "blech";
	if (!t1.parse(5, av) &&
	        t1.errmsg() ==  "-tex: \"blech\" is not a valid floating-point number")
		ok++;

	if (ok == 2)
	{
		cout << "PASS" << endl;
	}
	else
	{
		cout << "FAIL" << endl;
		bad++;
	}

	ok = 0;
	cout << "Testing usage message... ";

	ArgParse::apflag junkf;
	ArgParse t2;
	t2.usageHeader("GNU `tar' saves blah, blah, blah\n\n"
	               "Main operation mode:", 26);
	t2.argFlag("t", "\alist the contents of an archive", &junkf);
	t2.argFlag("x", "\aextract files from an archive", &junkf);
	t2.argFlag("delete",
	           "\adelete from the archive (not on mag tapes!)", &junkf);
	t2.alias("t", "list");
	t2.alias("x", "extract");
	t2.alias("x", "get");
	t2.usageHeader("\nOperation modifiers:", 29);
	t2.argFlag("G", "\ahandle old GNU-format incremental backup", &junkf);
	t2.argFlag("g", "=FILE\ahandle new GNU-format incremental backup", &junkf);
	t2.alias("G", "incremental");
	t2.alias("g", "listed-incremental");
	t2.usageHeader("\nArchive format selection:", 37);
	t2.argFlag("V", "=NAME\acreate archive with volume name NAME\n      "
	           "        PATTERN\aat list/extract time, a globbing PATTERN",
	           &junkf);
	t2.alias("V", "label");
	t2.allowOneCharOptionsToBeCombined();
	if (t2.usagemsg() ==
	        "GNU `tar' saves blah, blah, blah\n"
	        "\n"
	        "Main operation mode:\n"
	        "  -t, --list              list the contents of an archive\n"
	        "  -x, --get, --extract    extract files from an archive\n"
	        "      --delete            delete from the archive (not on mag tapes!)\n"
	        "\n"
	        "Operation modifiers:\n"
	        "  -G, --incremental          handle old GNU-format incremental backup\n"
	        "  -g, --listed-incremental=FILE\n"
	        "                             handle new GNU-format incremental backup\n"
	        "\n"
	        "Archive format selection:\n"
	        "  -V, --label=NAME                   create archive with volume name NAME\n"
	        "              PATTERN                at list/extract time, a globbing PATTERN\n")
		ok++;

	if (ok == 1)
	{
		cout << "PASS" << endl;
	}
	else
	{
		cout << "FAIL" << endl;
		bad++;
	}

	ok = 0;
	cout << "Testing arrays... ";
	ArgParse::apintvec foo;
	ArgParse::apfloatvec bar;
	ArgParse::apstringvec baz;
	ArgParse t3;
	t3.argInts("foo", "", &foo);
	t3.argFloats("bar", "", &bar);
	t3.argStrings("baz", "", &baz);

	av[0] = "eins";
	av[1] = "-baz=one";
	av[2] = "-foo=1";
	av[3] = "zwei";
	av[4] = "drei";
	av[5] = "-baz";
	av[6] = "two";
	av[7] = "vier";
	av[8] = "-foo=2";
	av[9] = "-bar=1";
	av[10] = "-bar=2";
	av[11] = "-bar";
	av[12] = "3";
	av[13] = "-bar:4";
	av[14] = "-foo=3";
	av[15] = "--baz=three";
	av[16] = "-baz:four";
	av[17] = "-foo=4";
	if (t3.parse(18, av) && checkArrays(foo, bar, baz, t3.leftovers()))
		ok++;

	foo.clear();
	bar.clear();
	baz.clear();
	ArgParse t4;
	t4.argInts("foo", "", &foo, ArgParse::SEP_ARGV);
	t4.argFloats("bar", "", &bar, ArgParse::SEP_ARGV);
	t4.argStrings("baz", "", &baz, ArgParse::SEP_ARGV);
	av[0] = "eins";
	av[1] = "zwei";
	av[2] = "-baz=one";
	av[3] = "two";
	av[4] = "-foo";
	av[5] = "1";
	av[6] = "2";
	av[7] = "3";
	av[8] = "-baz=three";
	av[9] = "-bar=1";
	av[10] = "-bar=2";
	av[11] = "-bar";
	av[12] = "3";
	av[13] = "4";
	av[14] = "-foo=4";
	av[15] = "--baz";
	av[16] = "four";
	av[17] = "--";
	av[18] = "drei";
	av[19] = "vier";
	if (t4.parse(20, av) && checkArrays(foo, bar, baz, t4.leftovers()))
		ok++;

	foo.clear();
	bar.clear();
	baz.clear();
	ArgParse t5;
	t5.argInts("foo", "", &foo, ',');
	t5.argFloats("bar", "", &bar, ',');
	t5.argStrings("baz", "", &baz, ',');
	av[0] = "-foo";
	av[1] = "1,2";
	av[2] = "eins";
	av[3] = "-baz=one,two,three";
	av[4] = "zwei";
	av[5] = "-bar:1,2,3,4";
	av[6] = "--baz=four";
	av[7] = "drei";
	av[8] = "-foo";
	av[9] = "3,4";
	av[10] = "vier";
	if (t5.parse(11, av) && checkArrays(foo, bar, baz, t5.leftovers()))
		ok++;

	if (ok == 3)
	{
		cout << "PASS" << endl;
	}
	else
	{
		cout << "FAIL" << endl;
		bad++;
	}

	return bad;
}