19#ifdef WITH_CYCLES_STANDALONE_GUI
33#ifdef WITH_CYCLES_STANDALONE_GUI
59 static int maxlen = 0;
60 const int len =
str.size();
63 for (
int i =
len;
i < maxlen;
i++) {
78 options.session->progress.get_status(status, substatus);
80 if (!substatus.empty()) {
81 status +=
": " + substatus;
107 HD_CYCLES_NS::HdCyclesFileReader::read(
options.session.get(),
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
160 pass->set_name(ustring(
options.output_pass.c_str()));
179#ifdef WITH_CYCLES_STANDALONE_GUI
182 static double latency = 0.0;
183 static double last = 0;
184 const double elapsed =
time_dt();
188 latency = (elapsed - last);
197 progress.get_status(status, substatus);
198 const double progress_val =
progress.get_progress();
200 if (!substatus.empty()) {
201 status +=
": " + substatus;
204 interactive =
options.interactive ?
"On" :
"Off";
218 interactive.c_str());
231 display_info(
options.session->progress);
234static void motion(
const int x,
const int y,
int button)
246 else if (button == 2) {
255 options.session->scene->camera->set_matrix(matrix);
256 options.session->scene->camera->need_flags_update =
true;
257 options.session->scene->camera->need_device_update =
true;
263static void resize(
const int width,
const int height)
272 options.session->scene->camera->compute_auto_viewplane();
273 options.session->scene->camera->need_flags_update =
true;
274 options.session->scene->camera->need_device_update =
true;
280static void keyboard(
unsigned char key)
288 else if (key ==
'r') {
293 else if (key == 27) {
294 options.session->progress.set_cancel(
"Canceled");
298 else if (key ==
'p') {
304 else if (key ==
'i') {
309 else if (
options.interactive && (key ==
'w' || key ==
'a' || key ==
's' || key ==
'd')) {
316 else if (key ==
's') {
319 else if (key ==
'a') {
322 else if (key ==
'd') {
329 options.session->scene->camera->set_matrix(matrix);
330 options.session->scene->camera->need_flags_update =
true;
331 options.session->scene->camera->need_device_update =
true;
337 else if (
options.interactive && (key ==
'0' || key ==
'1' || key ==
'2' || key ==
'3')) {
357 options.session->scene->integrator->set_max_bounce(bounce);
370static void parse_string(OIIO::cspan<const char *> argv, std::string *s)
383 options.session_params.use_auto_tile =
false;
384 options.session_params.tile_size = 0;
388 string devicename =
"CPU";
394 if (!device_names.empty()) {
395 device_names +=
", ";
402 string ssname =
"svm";
407 bool profile =
false;
409 bool version =
false;
412 ap.usage(
"cycles [options] file.xml");
413 ap.arg(
"filename").hidden().action([&](
auto argv) {
options.filepath = argv[0]; });
414 ap.arg(
"--device %s:DEVICE").help(
"Devices to use: " + device_names).action([&](
auto argv) {
418 ap.arg(
"--shadingsys %s:SHADINGSYSTEM")
419 .help(
"Shading system to use: svm, osl")
420 .action([&](
auto argv) {
parse_string(argv, &ssname); });
422 ap.arg(
"--background", &
options.session_params.background)
423 .help(
"Render in background, without user interface");
424 ap.arg(
"--quiet", &
options.quiet).help(
"In background mode, don't print progress messages");
425 ap.arg(
"--samples %d:SAMPLES").help(
"Number of samples to render").action([&](
auto argv) {
428 ap.arg(
"--output %s:OUTPUT").help(
"File path to write output image").action([&](
auto argv) {
431 ap.arg(
"--threads %d:THREADS").help(
"CPU Rendering Threads").action([&](
auto argv) {
434 ap.arg(
"--width %d:WIDTH").help(
"Image width in pixelx").action([&](
auto argv) {
437 ap.arg(
"--height %d:HEIGHT").help(
"Image height in pixel").action([&](
auto argv) {
440 ap.arg(
"--tile-size %d:TILE_SIZE").help(
"Tile size in pixels").action([&](
auto argv) {
443 ap.arg(
"--list-devices", &list).help(
"List information about all available devices");
444 ap.arg(
"--profile", &profile).help(
"Enable profile logging");
445#ifdef WITH_CYCLES_LOGGING
446 ap.arg(
"--debug", &debug).help(
"Enable debug logging");
447 ap.arg(
"--verbose %d:VERBOSE").help(
"Set verbosity of the logger").action([&](
auto argv) {
451 ap.arg(
"--help", &help).help(
"Print help message");
452 ap.arg(
"--version", &version).help(
"Print version number");
454 if (ap.parse_args(argc, argv) < 0) {
455 fprintf(stderr,
"%s\n", ap.geterror().c_str());
472 info.description.c_str(),
473 (info.display_device) ?
" (display)" :
"");
482 else if (help ||
options.filepath.empty()) {
487 options.session_params.use_profiling = profile;
489 if (ssname ==
"osl") {
492 else if (ssname ==
"svm") {
496#ifndef WITH_CYCLES_STANDALONE_GUI
497 options.session_params.background =
true;
500 if (
options.session_params.tile_size > 0) {
501 options.session_params.use_auto_tile =
true;
508 bool device_available =
false;
509 if (!devices.empty()) {
510 options.session_params.device = devices.front();
511 device_available =
true;
516 fprintf(stderr,
"Unknown device: %s\n", devicename.c_str());
520 else if (!(ssname ==
"osl" || ssname ==
"svm")) {
521 fprintf(stderr,
"Unknown shading system: %s\n", ssname.c_str());
527 fprintf(stderr,
"OSL shading system only works with CPU device\n");
531 else if (
options.session_params.samples < 0) {
532 fprintf(stderr,
"Invalid number of samples: %d\n",
options.session_params.samples);
535 else if (
options.filepath.empty()) {
536 fprintf(stderr,
"No file path specified\n");
545int main(
const int argc,
const char **argv)
551#ifdef WITH_CYCLES_STANDALONE_GUI
552 if (
options.session_params.background) {
557#ifdef WITH_CYCLES_STANDALONE_GUI
static DeviceType type_from_string(const char *name)
static vector< DeviceType > available_types()
static string string_from_type(DeviceType type)
static vector< DeviceInfo > available_devices(const uint device_type_mask=DEVICE_MASK_ALL)
static void session_init()
static void options_parse(const int argc, const char **argv)
static BufferParams & session_buffer_params()
static void session_print_status()
static void session_exit()
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)
VecBase< float, 4 > float4
#define assert(assertion)
void util_logging_verbosity_set(const int verbosity)
CCL_NAMESPACE_BEGIN void util_logging_init(const char *argv0)
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
unique_ptr< Session > session
CCL_NAMESPACE_BEGIN double time_dt()
#define CYCLES_VERSION_STRING
void window_opengl_context_disable()
bool window_opengl_context_enable()
void window_display_info(const char *info)
void window_main_loop(const char *title, const int width, const int height, WindowInitFunc initf, WindowExitFunc exitf, WindowResizeFunc resize, WindowDisplayFunc display, WindowKeyboardFunc keyboard, WindowMotionFunc motion)
void window_display_help()