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++) {
77 const double progress =
options.session->progress.get_progress();
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
180static void display_info(
Progress &progress)
182 static double latency = 0.0;
183 static double last = 0;
184 const double elapsed =
time_dt();
188 latency = (elapsed - last);
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;
408 bool version =
false;
411 ap.usage(
"cycles [options] file.xml");
412 ap.arg(
"filename").hidden().action([&](
auto argv) {
options.filepath = argv[0]; });
413 ap.arg(
"--device %s:DEVICE").help(
"Devices to use: " + device_names).action([&](
auto argv) {
417 ap.arg(
"--shadingsys %s:SHADINGSYSTEM")
418 .help(
"Shading system to use: svm, osl")
419 .action([&](
auto argv) {
parse_string(argv, &ssname); });
421 ap.arg(
"--background", &
options.session_params.background)
422 .help(
"Render in background, without user interface");
423 ap.arg(
"--quiet", &
options.quiet).help(
"In background mode, don't print progress messages");
424 ap.arg(
"--samples %d:SAMPLES").help(
"Number of samples to render").action([&](
auto argv) {
427 ap.arg(
"--output %s:OUTPUT").help(
"File path to write output image").action([&](
auto argv) {
430 ap.arg(
"--threads %d:THREADS").help(
"CPU Rendering Threads").action([&](
auto argv) {
433 ap.arg(
"--width %d:WIDTH").help(
"Image width in pixelx").action([&](
auto argv) {
436 ap.arg(
"--height %d:HEIGHT").help(
"Image height in pixel").action([&](
auto argv) {
439 ap.arg(
"--tile-size %d:TILE_SIZE").help(
"Tile size in pixels").action([&](
auto argv) {
442 ap.arg(
"--list-devices", &list).help(
"List information about all available devices");
443 ap.arg(
"--profile", &profile).help(
"Enable profile logging");
444 ap.arg(
"--log-level %s:LEVEL")
445 .help(
"Log verbosity: fatal, error, warning, info, stats, debug")
446 .action([&](
auto argv) {
parse_string(argv, &log_level); });
447 ap.arg(
"--help", &help).help(
"Print help message");
448 ap.arg(
"--version", &version).help(
"Print version number");
450 if (ap.parse_args(argc, argv) < 0) {
451 fprintf(stderr,
"%s\n", ap.geterror().c_str());
456 if (!log_level.empty()) {
467 info.description.c_str(),
468 (info.display_device) ?
" (display)" :
"");
477 else if (help ||
options.filepath.empty()) {
482 options.session_params.use_profiling = profile;
484 if (ssname ==
"osl") {
487 else if (ssname ==
"svm") {
491#ifndef WITH_CYCLES_STANDALONE_GUI
492 options.session_params.background =
true;
495 if (
options.session_params.tile_size > 0) {
496 options.session_params.use_auto_tile =
true;
503 bool device_available =
false;
504 if (!devices.empty()) {
505 options.session_params.device = devices.front();
506 device_available =
true;
511 fprintf(stderr,
"Unknown device: %s\n", devicename.c_str());
515 else if (!(ssname ==
"osl" || ssname ==
"svm")) {
516 fprintf(stderr,
"Unknown shading system: %s\n", ssname.c_str());
522 fprintf(stderr,
"OSL shading system only works with CPU device\n");
526 else if (
options.session_params.samples < 0) {
527 fprintf(stderr,
"Invalid number of samples: %d\n",
options.session_params.samples);
530 else if (
options.filepath.empty()) {
531 fprintf(stderr,
"No file path specified\n");
540int main(
const int argc,
const char **argv)
546#ifdef WITH_CYCLES_STANDALONE_GUI
547 if (
options.session_params.background) {
552#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)
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 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)
#define assert(assertion)
void log_init(const LogFunction func)
void log_level_set(const LogLevel level)
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()