Ejemplo n.º 1
0
void CoronaRenderer::render()
{
	OSL::OSLShadingNetworkRenderer *r = (OSL::OSLShadingNetworkRenderer *)getObjPtr("oslRenderer");
	if (r == NULL)
	{
		std::cerr << "error CoronaRenderer::render: OSL renderer == NULL\n";
		return;
	}
	this->oslRenderer = r;
	r->setup(); // delete existing shadingsys and reinit all

	//doit();
	//return;
	logger.debug(MString("Starting corona rendering..."));

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////  INIT SHADING CORE + SCEME
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    //Context context;
    context.core = ICore::createInstance();
    context.scene = context.core->createScene();
    context.logger = new mtco_Logger(context.core);

	logger.debug(MString("core/scene/logger..."));

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////  SETTINGS
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    context.settings = new Settings();
	context.colorMappingData = new Corona::ColorMappingData;

    // populate the settings with parameters from a configuration file. If the file does not exist, a new one 
    // is created with default values.
    ConfParser parser;
	
	Corona::String resPath = (getRendererHome() + "ressources/").asChar();
	logger.debug(MString("parser: ") + (resPath + CORONA_DEFAULT_CONF_FILENAME).cStr());
    parser.parseFile(resPath + CORONA_DEFAULT_CONF_FILENAME, context.settings, ConfParser::CREATE_IF_NONEXISTENT);

	logger.debug(MString("defineSettings..."));

	this->clearMaterialLists();
	this->defineSettings();
	logger.debug(MString("definePasses..."));
	this->definePasses();

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////  INTERNAL FRAME BUFFER
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    // create a new framebuffer, and init it before the rendering
	logger.debug(MString("createFb..."));
    context.fb = context.core->createFb();
    context.fb->initFb(context.settings, context.renderPasses);

	this->mtco_renderGlobals->getImageName();
	Corona::String dumpFilename = (this->mtco_renderGlobals->imageOutputFile + ".dmp").asChar();
	if (this->mtco_renderGlobals->dumpAndResume)
	{
		context.settings->set(Corona::PARAM_RANDOM_SEED, 0);
		if (!context.fb->accumulateFromExr(dumpFilename))
		{
			logger.debug(MString("Accumulating from a dumpfile failed: ") + dumpFilename.cStr());
		}
		else{
			// random seed has to be 0 for resuming a render
			context.settings->set(Corona::PARAM_RESUME_RENDERING, true);
			context.settings->set(Corona::PARAM_RANDOM_SEED, 0);
		}
	}
	createScene();
    context.core->sanityCheck(context.scene);
    context.core->sanityCheck(context.settings);

	Corona::String basePath = (this->mtco_renderGlobals->basePath + "/corona/").asChar();
	logger.debug(MString("beginSession..."));
	ICore::AdditionalInfo info;
	info.defaultFilePath = basePath;
    context.core->beginSession(context.scene, context.settings, context.fb, context.logger, info);
    
    // run the rendering. This function blocks until it is done
	logger.debug(MString("renderFrame..."));
    context.core->renderFrame();
	context.isCancelled = true;
    context.core->endSession();
	this->saveImage();

    // delete what we have created and call deallocation functions for objects the core has created
    delete context.logger;
    delete context.settings;
    
    for(auto it = context.renderPasses.begin(); it != context.renderPasses.end(); ++it) 
	{
        context.core->destroyRenderPass(*it);
    }

    context.core->destroyScene(context.scene);
    context.core->destroyFb(context.fb);
    ICore::destroyInstance(context.core);	
	context.core = NULL;
	context.fb = NULL;
	context.renderPasses.clear();
	context.isCancelled = false;
	context.scene = NULL;
	// for sequence rendering, at the moment clean up pointers
	// will be removed if I restructure the geo updates

	for( size_t objId = 0; objId < this->mtco_scene->objectList.size(); objId++)
	{
		mtco_MayaObject *obj = (mtco_MayaObject *)this->mtco_scene->objectList[objId];
		obj->geom = NULL;
		obj->instance = NULL;
	}
}
Ejemplo n.º 2
0
// init all data which will be used during a rendering.
// These data will be reused in rendering until the rendering is done.
void CoronaRenderer::initializeRenderer()
{
	Logging::debug("CoronaRenderer::initializeRenderer()");
	MFnDependencyNode gFn(getRenderGlobalsNode());
	clearDataList(); // clear nativeMtlData

	if (MGlobal::mayaState() != MGlobal::kBatch)
		MayaTo::getWorldPtr()->setRenderType(MayaTo::MayaToWorld::WorldRenderType::UIRENDER);
	else
		MayaTo::getWorldPtr()->setRenderType(MayaTo::MayaToWorld::WorldRenderType::BATCHRENDER);

	// first we delete any still existing elements.
	// after a render, the framebuffers, core and passes still exist until a new scene is loaded
	// or a new rendering is started.
	if (context.logger != nullptr)
	{
		delete context.logger;
		context.logger = nullptr;
	}
	if (context.settings != nullptr)
	{
		delete context.settings;
		context.settings = nullptr;
	}
	context.renderPasses.clear();
	if (context.fb != nullptr)
	{
		context.core->destroyFb(context.fb);
		context.fb = nullptr;
	}
	if (context.scene != nullptr)
	{
		context.core->destroyScene(context.scene);
		context.scene = nullptr;
	}
	if (context.core != nullptr)
	{
		ICore::destroyInstance(context.core);
		context.core = nullptr;
	}
	if (context.colorMappingData != nullptr)
	{
		delete context.colorMappingData;
		context.colorMappingData = nullptr;
	}

	context.settings = new Settings();
	context.core = ICore::createInstance();
	context.logger = new mtco_Logger(context.core);
	context.colorMappingData = new Corona::ColorMappingData;
	
	if (gFn.findPlug("useCoronaVFB").asBool())
		if (MGlobal::mayaState() != MGlobal::kBatch)
			vfbCallbacks.core = context.core;

	ConfParser parser;
	Corona::String resPath = (getRendererHome() + "resources/").asChar();
	Logging::debug(MString("parser: ") + (resPath + CORONA_DEFAULT_CONF_FILENAME).cStr());
	parser.parseFile(resPath + CORONA_DEFAULT_CONF_FILENAME, context.settings, ConfParser::CREATE_IF_NONEXISTENT);

	this->defineSettings();
	this->defineColorMapping();
	this->definePasses();
	context.fb = context.core->createFb();
	context.fb->initFb(context.settings, context.renderPasses);
	context.core->sanityCheck(context.settings);

	if (gFn.findPlug("useCoronaVFB").asBool())
		if (MGlobal::mayaState() != MGlobal::kBatch)
			context.core->getWxVfb().renderStarted(context.fb, &vfbCallbacks, IWxVfb::EnviroConfig());

	// this can be extracted and placed in a button function in the render globals
	std::shared_ptr<RenderGlobals> renderGlobals = MayaTo::getWorldPtr()->worldRenderGlobalsPtr;
	MFnDependencyNode renderGlobalsNode(getRenderGlobalsNode());
	Corona::String dumpFilename = (renderGlobals->getImageOutputFile() + ".dmp").asChar();
	if (getBoolAttr("dumpAndResume", renderGlobalsNode, false))
	{
		context.settings->set(Corona::PARAM_RANDOM_SEED, 0);
		if (!context.fb->accumulateFromExr(dumpFilename))
		{
			Logging::debug(MString("Accumulating from a dumpfile failed: ") + dumpFilename.cStr());
		}
		else{
			// random seed has to be 0 for resuming a render
			context.settings->set(Corona::PARAM_RESUME_RENDERING, true);
			context.settings->set(Corona::PARAM_RANDOM_SEED, 0);
		}
	}

	OSL::OSLShadingNetworkRenderer *r = (OSL::OSLShadingNetworkRenderer *)MayaTo::getWorldPtr()->getObjPtr("oslRenderer");
	if (r == nullptr)
	{
		Logging::debug("error CoronaRenderer::render: OSL renderer == nullptr");
		return;
	}
	this->oslRenderer = r;
	r->setup(); // delete existing shadingsys and reinit all

}