Marko Pintera 12 лет назад
Родитель
Сommit
82a1cb6ee7

+ 13 - 0
BansheeEngine/Include/BsOverlay.h

@@ -29,10 +29,23 @@ namespace BansheeEngine
 
 		CM::Viewport* getTarget() const { return mRenderTarget; }
 
+		/**
+		 * @brief	Depth determines in which order the overlays render in case they overlap.
+		 * 			Smaller depth means the overlay is in front of anything with larger depth.
+		 */
+		INT32 getDepth() const { return mDepth; }
+
+		/**
+		 * @brief	Depth determines in which order the overlays render in case they overlap.
+		 * 			Smaller depth means the overlay is in front of anything with larger depth.
+		 */
+		void setDepth(INT32 depth) { mDepth = depth; }
+
 	protected:
 		friend class CM::SceneObject;
 
 		CM::Viewport* mRenderTarget;
+		INT32 mDepth;
 
 		Overlay(const CM::HSceneObject& parent);
 	};

+ 6 - 1
BansheeEngine/Include/BsOverlayManager.h

@@ -16,6 +16,11 @@ namespace BansheeEngine
 	 */
 	class BS_EXPORT OverlayManager : public CM::Module<OverlayManager>
 	{
+		struct OverlayComparer
+		{
+			bool operator() (const Overlay* const& a, const Overlay* const& b);
+		};
+
 	public:
 		void render(CM::ViewportPtr& target, CM::RenderContext& renderContext) const;
 
@@ -26,6 +31,6 @@ namespace BansheeEngine
 		void detachOverlay(const CM::Viewport* target, const Overlay* overlay);
 		void detachOverlayFromAll(const Overlay* overlay);
 
-		std::unordered_map<const CM::Viewport*, std::unordered_set<const Overlay*>> mOverlaysPerTarget;
+		std::unordered_map<const CM::Viewport*, std::set<const Overlay*, OverlayComparer>> mOverlaysPerTarget;
 	};
 }

+ 1 - 1
BansheeEngine/Source/BsOverlay.cpp

@@ -6,7 +6,7 @@ using namespace CamelotFramework;
 namespace BansheeEngine
 {
 	Overlay::Overlay(const HSceneObject& parent)
-		:Component(parent), mRenderTarget(nullptr)
+		:Component(parent), mRenderTarget(nullptr), mDepth(0)
 	{
 
 	}

+ 7 - 1
BansheeEngine/Source/BsOverlayManager.cpp

@@ -6,6 +6,11 @@ using namespace CamelotFramework;
 
 namespace BansheeEngine
 {
+	bool OverlayManager::OverlayComparer::operator() (const Overlay* const& a, const Overlay* const& b)
+	{
+		return a->getDepth() > b->getDepth();
+	}
+
 	void OverlayManager::render(CM::ViewportPtr& target, RenderContext& renderContext) const
 	{
 		auto overlays = mOverlaysPerTarget.find(target.get());
@@ -14,7 +19,8 @@ namespace BansheeEngine
 			return;
 
 		renderContext.setViewport(target);
-
+		
+		// Render all overlays. They should already be sorted by depth, front most rendering last
 		for(auto& overlay : overlays->second)
 		{
 			overlay->render(renderContext);