34#ifdef WITH_CYCLES_STANDALONE_GUI
60 static int maxlen = 0;
64 for (
int i =
len; i < maxlen; i++) {
74 string status, substatus;
77 double progress =
options.session->progress.get_progress();
78 options.session->progress.get_status(status, substatus);
80 if (substatus !=
"") {
81 status +=
": " + substatus;
85 status =
string_printf(
"Progress %05.2f %s", (
double)progress * 100, status.c_str());
107 HD_CYCLES_NS::HdCyclesFileReader::read(
options.session,
options.filepath.c_str());
126 options.scene->camera->compute_auto_viewplane();
131 options.output_pass =
"combined";
134#ifdef WITH_CYCLES_STANDALONE_GUI
135 if (!
options.session_params.background) {
136 options.session->set_display_driver(make_unique<OpenGLDisplayDriver>(
141 if (!
options.output_filepath.empty()) {
142 options.session->set_output_driver(make_unique<OIIOOutputDriver>(
149#ifdef WITH_CYCLES_STANDALONE_GUI
159 pass->set_name(ustring(
options.output_pass.c_str()));
179#ifdef WITH_CYCLES_STANDALONE_GUI
180static void display_info(
Progress &progress)
182 static double latency = 0.0;
183 static double last = 0;
185 string str, interactive;
187 latency = (elapsed - last);
191 string status, substatus;
198 status +=
": " + substatus;
200 interactive =
options.interactive ?
"On" :
"Off";
212 (
double)progress_val * 100,
214 interactive.c_str());
226 display_info(
options.session->progress);
229static void motion(
int x,
int y,
int button)
241 else if (button == 2) {
250 options.session->scene->camera->set_matrix(matrix);
251 options.session->scene->camera->need_flags_update =
true;
252 options.session->scene->camera->need_device_update =
true;
258static void resize(
int width,
int height)
267 options.session->scene->camera->compute_auto_viewplane();
268 options.session->scene->camera->need_flags_update =
true;
269 options.session->scene->camera->need_device_update =
true;
275static void keyboard(
unsigned char key)
287 options.session->progress.set_cancel(
"Canceled");
290 else if (key ==
'p') {
300 else if (
options.interactive && (key ==
'w' || key ==
'a' || key ==
's' || key ==
'd')) {
316 options.session->scene->camera->set_matrix(matrix);
317 options.session->scene->camera->need_flags_update =
true;
318 options.session->scene->camera->need_device_update =
true;
324 else if (
options.interactive && (key ==
'0' || key ==
'1' || key ==
'2' || key ==
'3')) {
344 options.session->scene->integrator->set_max_bounce(bounce);
351static void parse_int(OIIO::cspan<const char *> argv,
int *i)
353 assert(argv.size() == 2);
357static void parse_string(OIIO::cspan<const char *> argv, std::string *s)
359 assert(argv.size() == 2);
370 options.session_params.use_auto_tile =
false;
371 options.session_params.tile_size = 0;
374 string device_names =
"";
375 string devicename =
"CPU";
381 if (device_names !=
"") {
382 device_names +=
", ";
389 string ssname =
"svm";
393 bool help =
false, profile =
false, debug =
false, version =
false;
396 ap.usage(
"cycles [options] file.xml");
397 ap.arg(
"filename").hidden().action([&](
auto argv) {
options.filepath = argv[0]; });
398 ap.arg(
"--device %s:DEVICE").help(
"Devices to use: " + device_names).action([&](
auto argv) {
402 ap.arg(
"--shadingsys %s:SHADINGSYSTEM")
403 .help(
"Shading system to use: svm, osl")
404 .action([&](
auto argv) {
parse_string(argv, &ssname); });
406 ap.arg(
"--background", &
options.session_params.background)
407 .help(
"Render in background, without user interface");
408 ap.arg(
"--quiet", &
options.quiet).help(
"In background mode, don't print progress messages");
409 ap.arg(
"--samples %d:SAMPLES").help(
"Number of samples to render").action([&](
auto argv) {
412 ap.arg(
"--output %s:OUTPUT").help(
"File path to write output image").action([&](
auto argv) {
415 ap.arg(
"--threads %d:THREADS").help(
"CPU Rendering Threads").action([&](
auto argv) {
418 ap.arg(
"--width %d:WIDTH").help(
"Image width in pixelx").action([&](
auto argv) {
421 ap.arg(
"--height %d:HEIGHT").help(
"Image height in pixel").action([&](
auto argv) {
424 ap.arg(
"--tile-size %d:TILE_SIZE").help(
"Tile size in pixels").action([&](
auto argv) {
427 ap.arg(
"--list-devices", &list).help(
"List information about all available devices");
428 ap.arg(
"--profile", &profile).help(
"Enable profile logging");
429#ifdef WITH_CYCLES_LOGGING
430 ap.arg(
"--debug", &debug).help(
"Enable debug logging");
431 ap.arg(
"--verbose %d:VERBOSE").help(
"Set verbosity of the logger").action([&](
auto argv) {
435 ap.arg(
"--help", &help).help(
"Print help message");
436 ap.arg(
"--version", &version).help(
"Print version number");
438 if (ap.parse_args(argc, argv) < 0) {
439 fprintf(stderr,
"%s\n", ap.geterror().c_str());
466 else if (help ||
options.filepath ==
"") {
471 options.session_params.use_profiling = profile;
473 if (ssname ==
"osl") {
476 else if (ssname ==
"svm") {
480#ifndef WITH_CYCLES_STANDALONE_GUI
481 options.session_params.background =
true;
484 if (
options.session_params.tile_size > 0) {
485 options.session_params.use_auto_tile =
true;
492 bool device_available =
false;
493 if (!devices.empty()) {
494 options.session_params.device = devices.front();
495 device_available =
true;
500 fprintf(stderr,
"Unknown device: %s\n", devicename.c_str());
504 else if (!(ssname ==
"osl" || ssname ==
"svm")) {
505 fprintf(stderr,
"Unknown shading system: %s\n", ssname.c_str());
511 fprintf(stderr,
"OSL shading system only works with CPU device\n");
515 else if (
options.session_params.samples < 0) {
516 fprintf(stderr,
"Invalid number of samples: %d\n",
options.session_params.samples);
519 else if (
options.filepath ==
"") {
520 fprintf(stderr,
"No file path specified\n");
529int main(
int argc,
const char **argv)
535#ifdef WITH_CYCLES_STANDALONE_GUI
536 if (
options.session_params.background) {
541#ifdef WITH_CYCLES_STANDALONE_GUI
static vector< DeviceInfo > available_devices(uint device_type_mask=DEVICE_MASK_ALL)
static DeviceType type_from_string(const char *name)
static vector< DeviceType > available_types()
static string string_from_type(DeviceType type)
void get_status(string &status_, string &substatus_) const
void get_time(double &total_time_, double &render_time_) const
double get_progress() const
static void session_init()
static BufferParams & session_buffer_params()
static void session_print_status()
static void session_exit()
static void options_parse(int argc, const char **argv)
static void parse_string(OIIO::cspan< const char * > argv, std::string *s)
CCL_NAMESPACE_BEGIN struct Options options
static void session_print(const string &str)
static void parse_int(OIIO::cspan< const char * > argv, int *i)
void xml_read_file(Scene *scene, const char *filepath)
#define CCL_NAMESPACE_END
#define DEVICE_MASK(type)
CCL_NAMESPACE_BEGIN void util_logging_init(const char *argv0)
void util_logging_verbosity_set(int verbosity)
void util_logging_start()
MatBase< T, NumCol, NumRow > translate(const MatBase< T, NumCol, NumRow > &mat, const VectorT &translation)
string path_filename(const string &path)
void path_init(const string &path, const string &user_path)
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
bool string_endswith(const string_view s, const string_view end)
string string_to_lower(const string &s)
SessionParams session_params
VecBase< float, 4 > float4
CCL_NAMESPACE_BEGIN double time_dt()
#define CYCLES_VERSION_STRING
void window_main_loop(const char *title, int width, int height, WindowInitFunc initf, WindowExitFunc exitf, WindowResizeFunc resize, WindowDisplayFunc display, WindowKeyboardFunc keyboard, WindowMotionFunc motion)
void window_opengl_context_disable()
bool window_opengl_context_enable()
void window_display_info(const char *info)
void window_display_help()