コード例 #1
0
bool ParticleLiquidDrawStage::stepSimulation() throw(SimulatorException)
{
	URE_INSTANCE->getSimulator(VISUAL_SIM_DOMAIN)->toLightingSimulator()->getMainCamera()
		->setGLViewPort(
				Vector2Di(0,0),
				Vector2Di(WindowManager::getInstance().getWindowResolution())
	);

//	if(! mRenderToScreen)
//	{
//		//render to FBO
//		mUsedRenderTarget->bind();
//		RenderTarget::setEnableDepthTest(true);
//		mUsedRenderTarget->attachStoredColorTexture(FINAL_RENDERING_SEMANTICS,0);
//		mUsedRenderTarget->renderToAttachedTextures();
//	}

	//TODO continue


	//ensure that render target is unbound so that it's not used on accident by following stages
	RenderTarget::renderToScreen();
	//TODO maybe clear srceen? should actualle be done by dimulator at the beginning...

	//--------------------------------------------------
	//TEST: just render the result from previous stage as texture show to test the render target stuff

	//enable the texture show shader with the respective texture bound
	RenderTarget* rt =
			dynamic_cast<LightingSimStageBase*>(
			URE_INSTANCE->getSimulator(VISUAL_SIM_DOMAIN)
						->getStage("DefaultLightingStage"))->getUsedRenderTarget();
	assert(rt);

	Texture* renderingOfDefaultLightingStage =
		dynamic_cast<Texture*>(
			URE_INSTANCE->getSimulator(VISUAL_SIM_DOMAIN)
			->getStage("DefaultLightingStage")->getRenderingResult(FINAL_RENDERING_SEMANTICS)
		);
	assert("The DefaultLightingStage must expose a Texture with final rendering semantics! "
			&& renderingOfDefaultLightingStage);

	//render to FBO
	rt->bind();
	rt->detachAllColorTextures(); //free from previous stage's relicts
	rt->attachColorTexture(mCompositedRendering,0); //attach own texture

	RenderTarget::setEnableDepthTest(true);
	rt->attachStoredDepthBuffer();
	rt->renderToAttachedTextures();


	//haxx: just copy the texture to have both an image to sample from
	//and to amend by direct fluid rendering
	mTextureShowShader->use(renderingOfDefaultLightingStage);
	WindowManager::getInstance().drawFullScreenQuad();

	RenderTarget::setEnableDepthTest(true);

	//now, render fluid onto the just copied texture;
	//again: this hack is needed to have a consistent depth buffer!
	int numCurrentFluids =
			dynamic_cast<ParticleMechanicsStage*>(
				URE_INSTANCE->getSimulator(MECHANICAL_SIM_DOMAIN)
				->getStage("ParticleMechanicsStage")
			)->getParticleSceneRepresentation()
			->getNumCurrentFluids();

	for(int i=0; i< numCurrentFluids; i++)
	{
		ParticleFluid* fluid =
			dynamic_cast<ParticleMechanicsStage*>(
				URE_INSTANCE->getSimulator(MECHANICAL_SIM_DOMAIN)
					->getStage("ParticleMechanicsStage")
				)->getParticleSceneRepresentation()
				->getFluid(i);

		assert( ! fluid->getSubObjects(VISUAL_SIM_DOMAIN).empty());
		SubObject* so = fluid->getSubObjects(VISUAL_SIM_DOMAIN)[0];

		ParticleLiquidVisualMaterial* mat =
			dynamic_cast<ParticleLiquidVisualMaterial*>(so->getMaterial());
		assert(mat);

		RenderTarget::setEnableDepthTest(true);
		mat->mCompositionShader->use(so);
		so->getGeometry()->draw();

		//draw fullscreenquad
		//WindowManager::getInstance().drawFullScreenQuad();
	}

	//now, just show the result rendered into the FBO
	//damn, so many useless copies, but time pressure is forcing me to do so...
	RenderTarget::renderToScreen();
	mTextureShowShader->use(mCompositedRendering);
	WindowManager::getInstance().drawFullScreenQuad();



	//-------------------

	return true;

}