示例#1
0
int main(int argc, char *argv[]) {
#if defined(__GNUC__)
	set_terminate(SLGTerminate);
#endif

	try {
		cerr << "Usage: " << argv[0] << " [options] [configuration file]" << endl <<
				" -o [configuration file]" << endl <<
				" -f [scene file]" << endl <<
				" -w [window width]" << endl <<
				" -e [window height]" << endl <<
				" -g <disable OpenCL GPU device>" << endl <<
				" -p <enable OpenCL CPU device>" << endl <<
				" -n [native thread count]" << endl <<
				" -r [gpu thread count]" << endl <<
				" -l [set high/low latency mode]" << endl <<
				" -b <enable high latency mode>" << endl <<
				" -s [GPU workgroup size]" << endl <<
				" -t [halt time in secs]" << endl <<
				" -T <enable the telnet server>" << endl <<
				" -D [property name] [property value]" << endl <<
				" -d [current directory path]" << endl <<
				" -h <display this help and exit>" << endl;

		// Initialize FreeImage Library
		FreeImage_Initialise(TRUE);
		FreeImage_SetOutputMessage(FreeImageErrorHandler);

		bool batchMode = false;
		bool telnetServerEnabled = false;
		Properties cmdLineProp;
		for (int i = 1; i < argc; i++) {
			if (argv[i][0] == '-') {
				// I should check for out of range array index...

				if (argv[i][1] == 'h') exit(EXIT_SUCCESS);

				else if (argv[i][1] == 'o') {
					if (config)
						throw runtime_error("Used multiple configuration files");

					config = new RenderingConfig(argv[++i]);
				}

				else if (argv[i][1] == 'e') cmdLineProp.SetString("image.height", argv[++i]);

				else if (argv[i][1] == 'w') cmdLineProp.SetString("image.width", argv[++i]);

				else if (argv[i][1] == 'f') cmdLineProp.SetString("scene.file", argv[++i]);

				else if (argv[i][1] == 'p') cmdLineProp.SetString("opencl.cpu.use", "1");

				else if (argv[i][1] == 'g') cmdLineProp.SetString("opencl.gpu.use", "0");

				else if (argv[i][1] == 'l') cmdLineProp.SetString("opencl.latency.mode", argv[++i]);

				else if (argv[i][1] == 'n') cmdLineProp.SetString("opencl.nativethread.count", argv[++i]);

				else if (argv[i][1] == 'r') cmdLineProp.SetString("opencl.renderthread.count", argv[++i]);

				else if (argv[i][1] == 's') cmdLineProp.SetString("opencl.gpu.workgroup.size", argv[++i]);

				else if (argv[i][1] == 't') cmdLineProp.SetString("batch.halttime", argv[++i]);

				else if (argv[i][1] == 'T') telnetServerEnabled = true;

				else if (argv[i][1] == 'D') {
					cmdLineProp.SetString(argv[i + 1], argv[i + 2]);
					i += 2;
				}

				else if (argv[i][1] == 'd') boost::filesystem::current_path(boost::filesystem::path(argv[++i]));

				else {
					cerr << "Invalid option: " << argv[i] << endl;
					exit(EXIT_FAILURE);
				}
			} else {
				string s = argv[i];
				if ((s.length() >= 4) && (s.substr(s.length() - 4) == ".cfg")) {
					if (config)
						throw runtime_error("Used multiple configuration files");
					config = new RenderingConfig(s);
				} else
					throw runtime_error("Unknow file extension: " + s);
			}
		}

		if (!config)
			config = new RenderingConfig("scenes/luxball/render-fast.cfg");

		config->cfg.Load(cmdLineProp);

		const unsigned int halttime = config->cfg.GetInt("batch.halttime", 0);
		const unsigned int haltspp = config->cfg.GetInt("batch.haltspp", 0);
		if ((halttime > 0) || (haltspp > 0))
			batchMode = true;
		else
			batchMode = false;

		if (batchMode) {
			config->Init();
			return BatchMode(halttime, haltspp);
		} else {
			// It is important to initialize OpenGL before OpenCL
			unsigned int width = config->cfg.GetInt("image.width", 640);
			unsigned int height = config->cfg.GetInt("image.height", 480);

			InitGlut(argc, argv, width, height);

			config->Init();

			if (telnetServerEnabled) {
				TelnetServer telnetServer(18081, config);
				RunGlut();
			} else
				RunGlut();
		}
#if !defined(LUXRAYS_DISABLE_OPENCL)
	} catch (cl::Error err) {
		cerr << "OpenCL ERROR: " << err.what() << "(" << err.err() << ")" << endl;
#endif
	} catch (runtime_error err) {
		cerr << "RUNTIME ERROR: " << err.what() << endl;
	} catch (exception err) {
		cerr << "ERROR: " << err.what() << endl;
	}

	return EXIT_SUCCESS;
}
示例#2
0
int main(int argc, char *argv[]) {
#if defined(__GNUC__) && !defined(__CYGWIN__)
	set_terminate(SLGTerminate);
#endif

	// This is required to run AMD GPU profiler
    //XInitThreads();

	luxrays::sdl::LuxRaysSDLDebugHandler = SDLDebugHandler;

	try {

		// Initialize FreeImage Library
		FreeImage_Initialise(TRUE);
		FreeImage_SetOutputMessage(FreeImageErrorHandler);

		bool batchMode = false;
		bool telnetServerEnabled = false;
		Properties cmdLineProp;
		RenderConfig *config = NULL;
		for (int i = 1; i < argc; i++) {
			if (argv[i][0] == '-') {
				// I should check for out of range array index...

				if (argv[i][1] == 'h') {
					SLG_LOG("Usage: " << argv[0] << " [options] [configuration file]" << endl <<
							" -o [configuration file]" << endl <<
							" -f [scene file]" << endl <<
							" -w [window width]" << endl <<
							" -e [window height]" << endl <<
							" -t [halt time in secs]" << endl <<
							" -T <enable the telnet server>" << endl <<
							" -D [property name] [property value]" << endl <<
							" -d [current directory path]" << endl <<
							" -m Makes the mouse operations work in \"grab mode\"" << endl << 
							" -h <display this help and exit>");
					exit(EXIT_SUCCESS);
				}
				else if (argv[i][1] == 'o') {
					if (config)
						throw runtime_error("Used multiple configuration files");

					config = new RenderConfig(argv[++i]);
				}

				else if (argv[i][1] == 'e') cmdLineProp.SetString("image.height", argv[++i]);

				else if (argv[i][1] == 'w') cmdLineProp.SetString("image.width", argv[++i]);

				else if (argv[i][1] == 'f') cmdLineProp.SetString("scene.file", argv[++i]);

				else if (argv[i][1] == 't') cmdLineProp.SetString("batch.halttime", argv[++i]);

				else if (argv[i][1] == 'T') telnetServerEnabled = true;

				else if (argv[i][1] == 'm') mouseGrabMode = true;

				else if (argv[i][1] == 'D') {
					cmdLineProp.SetString(argv[i + 1], argv[i + 2]);
					i += 2;
				}

				else if (argv[i][1] == 'd') boost::filesystem::current_path(boost::filesystem::path(argv[++i]));

				else {
					SLG_LOG("Invalid option: " << argv[i]);
					exit(EXIT_FAILURE);
				}
			} else {
				string s = argv[i];
				if ((s.length() >= 4) && (s.substr(s.length() - 4) == ".cfg")) {
					if (config)
						throw runtime_error("Used multiple configuration files");
					config = new RenderConfig(s);
				} else
					throw runtime_error("Unknown file extension: " + s);
			}
		}

		if (!config)
			config = new RenderConfig("scenes/luxball/render-fast.cfg");

		// Overtwirte properties with the one defined on command line
		// NOTE: few properties like accelerator.type, etc. (the one used
		// in RenderConfig() constructor can not be overwritten.
		config->cfg.Load(cmdLineProp);

		const unsigned int halttime = config->cfg.GetInt("batch.halttime", 0);
		const unsigned int haltspp = config->cfg.GetInt("batch.haltspp", 0);
		const float haltthreshold = config->cfg.GetFloat("batch.haltthreshold", -1.f);
		if ((halttime > 0) || (haltspp > 0) || (haltthreshold >= 0.f))
			batchMode = true;
		else
			batchMode = false;

		if (batchMode) {
			session = new RenderSession(config);
			return BatchMode(halttime, haltspp, haltthreshold);
		} else {
			// It is important to initialize OpenGL before OpenCL
			// (for OpenGL/OpenCL interoperability)
			unsigned int width = config->cfg.GetInt("image.width", 640);
			unsigned int height = config->cfg.GetInt("image.height", 480);

			InitGlut(argc, argv, width, height);

			session = new RenderSession(config);

			// Start the rendering
			session->Start();

			if (telnetServerEnabled) {
				TelnetServer telnetServer(18081, session);
				RunGlut();
			} else
				RunGlut();
		}
	} catch (cl::Error err) {
		SLG_LOG("OpenCL ERROR: " << err.what() << "(" << luxrays::utils::oclErrorString(err.err()) << ")");
	} catch (runtime_error err) {
		SLG_LOG("RUNTIME ERROR: " << err.what());
	} catch (exception err) {
		SLG_LOG("ERROR: " << err.what());
	}

	return EXIT_SUCCESS;
}