Пример #1
0
//[-------------------------------------------------------]
//[ Public virtual PLRenderer::SurfacePainter functions   ]
//[-------------------------------------------------------]
void SPScene::OnPaint(Surface &cSurface)
{
	// Get the used renderer
	Renderer &cRenderer = GetRenderer();

	// Get camera
	SNCamera *pCamera = nullptr;
	SceneRenderer *pSceneRenderer = nullptr;
	if (m_pCameraNodeHandler->GetElement()) {
		pCamera = static_cast<SNCamera*>(m_pCameraNodeHandler->GetElement());
		if (pCamera)
			pSceneRenderer = pCamera->GetSceneRenderer();
	}
	SNCamera::SetCamera(pCamera, &cRenderer);

	// Check the used scene renderer
	if (!pSceneRenderer)
		pSceneRenderer = GetDefaultSceneRenderer();

	// Check the used scene renderer
	if (pSceneRenderer) {
		// Get the root scene container
		SceneContainer *pRootContainer = GetRootContainer();
		if (pRootContainer) {
			// Get the cull query
			SQCull *pCullQuery = static_cast<SQCull*>(m_pCullQuery->GetElement());
			if (pCullQuery) {
				// Set camera (can be a null pointer)
				if (pCamera) {
					// Setup render query
					SceneContainer *pCameraContainer = pCamera->GetContainer();
					pCullQuery->SetCameraContainer((pCameraContainer && pCameraContainer->IsCell()) ? pCameraContainer : nullptr);
					pCullQuery->SetCameraPosition(pCamera->GetTransform().GetPosition());
					pCullQuery->SetViewFrustum(pCamera->GetFrustum(cRenderer.GetViewport()));
					pCullQuery->SetProjectionMatrix(pCamera->GetProjectionMatrix(cRenderer.GetViewport()));
					pCullQuery->SetViewMatrix(pCamera->GetViewMatrix());
					pCullQuery->SetViewProjectionMatrix(pCullQuery->GetProjectionMatrix()*pCamera->GetViewMatrix());
				} else {
					// Set default states
					pCullQuery->SetCameraContainer(nullptr);
					pCullQuery->SetCameraPosition(Vector3::Zero);
					Matrix4x4 mProj;
					mProj.PerspectiveFov(static_cast<float>(90.0f*Math::DegToRad), 1.0f, 0.001f, 10000.0f);
					Frustum cFrustum;
					cFrustum.CreateViewPlanes(mProj, false);
					pCullQuery->SetViewFrustum(cFrustum);
				}

				// Perform the visibility determination
				pCullQuery->PerformQuery();
			}

			// Get the scene container (can be a null pointer)
			SceneContainer *pContainer = GetSceneContainer();

			// Pre all scene nodes
			DrawPre(cRenderer, *pRootContainer);

			// Draw all scene nodes solid
			DrawSolid(cRenderer, *pRootContainer);

			// Draw the scene container (if there's one)
			if (pContainer && pCullQuery)
				pSceneRenderer->DrawScene(cRenderer, *pCullQuery);

			// Draw all scene nodes transparent
			DrawTransparent(cRenderer, *pRootContainer);

			// Debug all scene nodes
			DrawDebug(cRenderer, *pRootContainer);

			// Post all scene nodes
			DrawPost(cRenderer, *pRootContainer);
		}
	}
}