1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
|
/****************************************************************************
* povray.cpp
*
* This module contains the entry routine for the raytracer and the code to
* parse the parameters on the command line.
*
* from Persistence of Vision(tm) Ray Tracer version 3.6.
* Copyright 1991-2003 Persistence of Vision Team
* Copyright 2003-2004 Persistence of Vision Raytracer Pty. Ltd.
*---------------------------------------------------------------------------
* NOTICE: This source code file is provided so that users may experiment
* with enhancements to POV-Ray and to port the software to platforms other
* than those supported by the POV-Ray developers. There are strict rules
* regarding how you are permitted to use this file. These rules are contained
* in the distribution and derivative versions licenses which should have been
* provided with this file.
*
* These licences may be found online, linked from the end-user license
* agreement that is located at http://www.povray.org/povlegal.html
*---------------------------------------------------------------------------
* This program is based on the popular DKB raytracer version 2.12.
* DKBTrace was originally written by David K. Buck.
* DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
*---------------------------------------------------------------------------
* $File: //depot/povray/3.6-release/source/povray.cpp $
* $Revision: #3 $
* $Change: 3032 $
* $DateTime: 2004/08/02 18:43:41 $
* $Author: chrisc $
* $Log$
*****************************************************************************/
#include <ctype.h>
#include <time.h>
#include <algorithm>
#include "frame.h"
#include "bezier.h"
#include "blob.h"
#include "bbox.h"
#include "cones.h"
#include "csg.h"
#include "discs.h"
#include "express.h"
#include "fnpovfpu.h"
#include "fractal.h"
#include "hfield.h"
#include "lathe.h"
#include "lighting.h"
#include "lightgrp.h"
#include "mesh.h"
#include "photons.h"
#include "polysolv.h"
#include "objects.h"
#include "octree.h"
#include "parse.h"
#include "parstxtr.h"
#include "pigment.h"
#include "point.h"
#include "poly.h"
#include "polygon.h"
#include "povray.h"
#include "optout.h"
#include "quadrics.h"
#include "prism.h"
#include "radiosit.h"
#include "render.h"
#include "sor.h"
#include "spheres.h"
#include "super.h"
#include "targa.h"
#include "texture.h"
#include "tokenize.h"
#include "torus.h"
#include "triangle.h"
#include "truetype.h"
#include "userio.h"
#include "userdisp.h"
#include "lbuffer.h"
#include "vbuffer.h"
#include "povmsend.h"
#include "povmsrec.h"
#include "isosurf.h"
#include "sphsweep.h"
#include "pov_util.h"
#include "renderio.h"
#include "statspov.h"
#include "pov_err.h"
#include "optout.h"
#include "povms.h"
#include "rendctrl.h"
#include "platformbase.h"
#if(USE_LOCAL_POVMS_OUTPUT == 1)
#include "defaultrenderfrontend.h"
#include "defaultplatformbase.h"
#include "processrenderoptions.h"
USING_POV_FRONTEND_NAMESPACE
USING_POV_BASE_NAMESPACE
#endif
USING_POV_NAMESPACE
BEGIN_POV_NAMESPACE
/*****************************************************************************
* Local preprocessor defines
******************************************************************************/
#ifndef POVMS_ALLOW_BINARY_MODE
#ifdef ALTMAIN
#define POVMS_ALLOW_BINARY_MODE 0
#else
#define POVMS_ALLOW_BINARY_MODE 1
#endif
#endif
/*****************************************************************************
* Local typedefs
******************************************************************************/
/*****************************************************************************
* Global variables
******************************************************************************/
END_POV_NAMESPACE
bool Binary_POVMS_Stream_Mode = false; // GLOBAL VARIABLE
#ifdef POVRAY_COOPERATE_GLOBAL
POVRAY_COOPERATE_GLOBAL
#endif
BEGIN_POV_NAMESPACE
/*****************************************************************************
* Local variables
******************************************************************************/
// povray_init
int pre_init_flag = 0; // GLOBAL VARIABLE
// Used for povray_cooperate tricks
int Cooperate_Render_Flag = 0; // GLOBAL VARIABLE
END_POV_NAMESPACE
// Used for POVMS message receiving
POVMSContext POVMS_Render_Context = NULL; // GLOBAL VARIABLE
// Used for POVMS message sending
#if(USE_LOCAL_POVMS_OUTPUT == 1)
POVMSContext POVMS_Output_Context = NULL; // GLOBAL VARIABLE
#endif
// Platform specific function interface self reference pointer
PlatformBase *POV_BASE_NAMESPACE::PlatformBase::self = NULL; // GLOBAL VARIABLE
/*****************************************************************************
*
* FUNCTION
*
* main
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION
*
* -
*
* CHANGES
*
* -
*
******************************************************************************/
#ifndef ALTMAIN
int main(int argc, char **argv)
{
DefaultPlatformBase platformbase;
POVMSAddress addr = POVMSInvalidAddress;
int err = kNoErr;
int ret = 0;
int i = 0;
// Init
povray_init();
if(err == kNoErr)
err = POVMS_GetContextAddress(POVMS_Render_Context, &addr);
if(err != kNoErr)
(void)POVMS_ASSERT_OUTPUT("Accessing POVMS render context failed.", "povray.cpp", 0);
if(err == kNoErr)
err = POVMS_OpenContext(&POVMS_Output_Context);
if(err != kNoErr)
(void)POVMS_ASSERT_OUTPUT("Creating POVMS output context failed.", "povray.cpp", 0);
else
{
DefaultRenderFrontend frontend(POVMS_Output_Context, addr);
argc = GETCOMMANDLINE(argc, argv);
#if(POVMS_ALLOW_BINARY_MODE == 1)
// Binary control mode via POVMS on stdin and stdout
if((argc > 1) && (pov_stricmp(argv[1], "-povms") == 0))
Binary_POVMS_Stream_Mode = true;
#endif
// Print help screens
if(argc == 1)
{
frontend.PrintHelpScreens();
return 0;
}
else if(argc == 2)
{
if((pov_stricmp(argv[1], "-h") == 0) ||
(pov_stricmp(argv[1], "-?") == 0) ||
(pov_stricmp(argv[1], "--help") == 0) ||
(pov_stricmp(argv[1], "-help") == 0))
{
frontend.PrintHelpScreens();
return 0;
}
else if(argv[1][0] == '-')
{
if(argv[1][1] == '?')
{
frontend.PrintUsage(argv[1][2] - '0');
return 0;
}
else if(strlen(argv[1]) == 6)
{
if(((argv[1][1] == 'h') || (argv[1][1] == 'H')) &&
((argv[1][2] == 'e') || (argv[1][2] == 'E')) &&
((argv[1][3] == 'l') || (argv[1][3] == 'L')) &&
((argv[1][4] == 'p') || (argv[1][4] == 'P')))
{
frontend.PrintUsage(argv[1][5] - '0');
return 0;
}
}
}
}
// Render
#if(POVMS_ALLOW_BINARY_MODE == 1)
// Binary control mode via POVMS on stdin and stdout
if((argc > 1) && (pov_stricmp(argv[1], "-povms") == 0))
Binary_POVMS_Stream_Mode = true;
if(Binary_POVMS_Stream_Mode == true)
{
while(Cooperate_Render_Flag >= 0)
povray_cooperate();
return 0;
}
#endif
try
{
ProcessRenderOptions renderoptions;
POVMSObject obj;
int l = 0;
err = POVMSObject_New(&obj, kPOVObjectClass_ROptions);
if(err != kNoErr)
throw err;
for(i = 1 ;i < argc; i++)
{
if(pov_stricmp(argv[i], "-povms") != 0)
{
err = renderoptions.ParseString(argv[i], &obj, true);
if(err != kNoErr)
throw err;
}
}
if(POVMSUtil_GetStringLength(&obj, kPOVAttrib_CreateIni, &l) == kNoErr)
{
char *outputini = new char[l];
if(POVMSUtil_GetString(&obj, kPOVAttrib_CreateIni, outputini, &l) == kNoErr)
renderoptions.WriteFile(outputini, &obj);
}
POVMS_Object optionsobj(obj);
frontend.StartRender(optionsobj);
while(frontend.GetState() != RenderFrontend::kReady)
povray_cooperate();
}
catch(int err)
{
fprintf(stderr, "Failed to render file due to error(s)!\n");
return err;
}
catch(const char *str)
{
fprintf(stderr, "%s\n Failed to render file!\n", str);
return -1;
}
catch(...)
{
fprintf(stderr, "Failed to render file due to error(s)!\n");
return -1;
}
// NOTE: It is important that 'frontend' be destroyed in this block scope because
// 'POVMS_CloseContext' will destroy the render context too early otherwise!
}
// Finish
povray_terminate();
(void)POVMS_CloseContext(POVMS_Output_Context);
return ret;
}
#endif
/*****************************************************************************
*
* FUNCTION
*
* povray_init
*
* INPUT -- none
*
* OUTPUT
*
* RETURNS
*
* AUTHOR -- CEY
*
* DESCRIPTION
*
* This routine does essential initialization that is required before any
* POV_MALLOC-like routines may be called and before any text streams and
* the POVMS may be used.
*
* If you are not using any built-in main and need access to any part of
* the generic code before povray_render is called, you MUST call this routine
* first! Also note that it is safe to call it twice. If you don't call it,
* povray_render will. It won't hurt if you both do it.
*
* CHANGES
* Nov 1995 : Created by CEY
*
******************************************************************************/
void povray_init()
{
Stage = STAGE_PREINIT;
if (pre_init_flag == 0)
{
int err;
Cooperate_Render_Flag = 0;
err = POVMS_OpenContext(&POVMS_Render_Context);
if(err == 0)
err = POVMS_InstallReceiver(POVMS_Render_Context, Receive_RenderOptions, kPOVMsgClass_RenderControl, kPOVMsgIdent_RenderOptions, NULL);
if(err == 0)
err = POVMS_InstallReceiver(POVMS_Render_Context, Receive_RenderAll, kPOVMsgClass_RenderControl, kPOVMsgIdent_RenderAll, NULL);
if(err == 0)
err = POVMS_InstallReceiver(POVMS_Render_Context, Receive_RenderArea, kPOVMsgClass_RenderControl, kPOVMsgIdent_RenderArea, NULL);
if(err == 0)
err = POVMS_InstallReceiver(POVMS_Render_Context, Receive_RenderStop, kPOVMsgClass_RenderControl, kPOVMsgIdent_RenderStop, NULL);
if(err != 0)
(void)POVMS_ASSERT_OUTPUT("Installing POVMS receive handler functions failed.", "povray.cpp", 0);
}
/* Initialize memory. */
POV_MEM_INIT();
pre_init_tokenizer();
pre_init_flag = 1234;
}
/*****************************************************************************
*
* FUNCTION
*
* povray_terminate
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION
*
* -
*
* CHANGES
*
* -
*
******************************************************************************/
void povray_terminate()
{
close_all();
POV_MEM_RELEASE_ALL();
(void)POVMS_CloseContext(POVMS_Render_Context);
pre_init_flag = 0;
FINISH_POVRAY;
}
/*****************************************************************************
*
* FUNCTION
*
* povray_exit
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION
*
* -
*
* CHANGES
*
* -
*
******************************************************************************/
void povray_exit(int i)
{
if(Stop_Flag)
{
Send_Progress("Aborting render!", PROGRESS_ABORTING_RENDER);
if(POV_SHELLOUT(USER_ABORT_SHL) != FATAL_RET)
Send_Progress("User abort", PROGRESS_USER_ABORT);
else // Do *not* call "Error" here because it would in turn call povray_exit! [trf]
PossibleError("Fatal error in User_Abort_Command.");
}
if(Stage == STAGE_PARSING)
{
Terminate_Tokenizer();
Destroy_Textures(Default_Texture);
Destroy_Camera(Default_Camera);
}
Do_Cooperate(0);
pre_init_flag = 1;
Cooperate_Render_Flag = 3;
EXIT_POVRAY(i); /* Must call exit(i) or somehow stop */
}
/*****************************************************************************
*
* FUNCTION
*
* povray_cooperate
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION
*
* -
*
* CHANGES
*
* -
*
******************************************************************************/
void povray_cooperate()
{
bool withtime = false;
POVRAY_BEGIN_COOPERATE
switch(Cooperate_Render_Flag)
{
case 0:
Cooperate_Render_Flag = 1;
// Call init
povray_init();
// Startup povray
Stage = STAGE_STARTUP;
STARTUP_POVRAY
// Print banner and credit info
Stage = STAGE_BANNER;
Send_InitInfo();
// Initialize variables
init_vars();
break;
case 1:
// Take option setting message, only render message receive
// handler switches to next state
(void)POVMS_ProcessMessages(POVMS_Render_Context, true);
break;
case 2:
// RenderDone message will include time statistics
withtime = true;
// Send start notification
Send_RenderStarted(opts.Options & CONTINUE_TRACE);
// Strip path and extension off input name to create scene name
fix_up_scene_name();
// Make sure clock is okay, validate animation parameters
fix_up_animation_values();
// Fix-up rendering window values if necessary
fix_up_rendering_window();
// Set output file handle for options screen
init_output_file_handle();
// Print options used.
Send_RenderOptions();
// Enter the frame loop
FrameLoop();
// Drop through (intentional)
case 3:
// Clean up
close_all();
// Free all memory
POV_MEM_RELEASE_ALL();
// Send end notification
Send_RenderDone(withtime);
withtime = false;
Cooperate_Render_Flag = 1;
#if(POVMS_ALLOW_BINARY_MODE == 1)
if(Binary_POVMS_Stream_Mode == false)
{
Cooperate_Render_Flag = -1;
break;
}
#endif
init_vars();
break;
}
POVRAY_END_COOPERATE
Do_Cooperate(2);
}
/*****************************************************************************
*
* FUNCTION
*
* povray_getoutputcontext
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION
*
* -
*
* CHANGES
*
* -
*
******************************************************************************/
#if(USE_LOCAL_POVMS_OUTPUT == 1)
POVMSAddress povray_getoutputcontext()
{
POVMSAddress addr = POVMSInvalidAddress;
if(POVMS_GetContextAddress(POVMS_Output_Context, &addr) != kNoErr)
return POVMSInvalidAddress;
return addr;
}
#endif
BEGIN_POV_NAMESPACE
/*****************************************************************************
*
* FUNCTION
*
* Do_Cooperate
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION
*
* -
*
* CHANGES
*
* -
*
******************************************************************************/
void Do_Cooperate(int level)
{
switch(level)
{
case 2:
default:
COOPERATE_2
case 0:
while(POVMS_ProcessMessages(POVMS_Render_Context, false) == kFalseErr)
{
}
#if(USE_LOCAL_POVMS_OUTPUT == 1)
while(POVMS_ProcessMessages(POVMS_Output_Context, false) == kFalseErr)
{
}
#endif
COOPERATE_0
break;
case 1:
COOPERATE_1
break;
};
}
END_POV_NAMESPACE
|