Пример #1
0
	bool RenderTarget::_readyDrawCalls()
	{
		mTriangleCount = 0;
		mBatchCount = 0;
		mSavedByBatching = 0;

		// If theres no camera, nothing to render
		if (!mCamera) return false;

		// Get the cameras parent, if its not attached to anything, theres nothing to render
		SceneNode* camParent = mCamera->getParent();
		if (!camParent) return false;

		// Find the highest node in the hierarchy
		SceneNode* rootNode = camParent->getRootNode();
		if (!rootNode) return false;

		Main::getRenderSystem().clear(glm::vec4(0.1,0.1,0.1, 1), GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		mCachedRenderableList.clear();
		rootNode->_getRenderables(mCachedRenderableList, mCamera, true);

		mCachedDrawCallList.clear();
		for (auto iter : mCachedRenderableList)
			iter->_extractDrawCalls(mCachedDrawCallList, *mCamera);

		std::sort(mCachedDrawCallList.begin(), mCachedDrawCallList.end(),
			[](const Renderable::DrawCall& first, const Renderable::DrawCall& second)
		{
			return first.sortKey.key < second.sortKey.key;
		});

		// Update the render system with the camera data
		glm::mat4 camMatrix = mCamera->getParent()->getGlobalTransform();
		glm::mat4 viewMatrix = glm::inverse(camMatrix);
		ngRenderSys.setCameraMatrices(mCamera->getProjMatrix(), viewMatrix, camMatrix);



		return true;
	}