Marko Pintera 11 лет назад
Родитель
Сommit
04beda4785
1 измененных файлов с 92 добавлено и 0 удалено
  1. 92 0
      BansheeCore/Include/BsMeshRenderData.h

+ 92 - 0
BansheeCore/Include/BsMeshRenderData.h

@@ -0,0 +1,92 @@
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsBounds.h"
+#include "BsSubMesh.h"
+
+namespace BansheeEngine
+{
+	/**
+	* Mesh render data provides a link between a Mesh and a Renderer. It may be modified
+	* by both as changes occur and as the mesh is used in the renderer. Essentially it allows
+	* the two to communicate without knowing about each other.
+	*/
+	class BS_CORE_EXPORT MeshRenderData
+	{
+	public:
+		/**
+		 * Creates a new empty render data.
+		 */
+		MeshRenderData() {}
+
+		/**
+		 * Creates render render data pointing to the specified vertex and index buffer, referencing
+		 * the provided sub-mesh index range.
+		 */
+		MeshRenderData(const std::shared_ptr<VertexData>& vertexData, const IndexBufferPtr& indexBuffer, 
+			const SubMesh& subMesh, UINT32 vertexOffset, std::function<void()> usedOnGPUcallback);
+
+		/**
+		 * Registers a new renderable proxy that references this mesh.
+		 */
+		void addRenderableProxy(RenderableSubProxy* proxy);
+
+		/**
+		 * Unregisters a renderable proxy that references this mesh.
+		 */
+		void removeRenderableProxy(RenderableSubProxy* proxy);
+
+		/**
+		 * Update mesh local bounds with the new provided bounds.
+		 */
+		void updateBounds(const Bounds& bounds);
+
+		/**
+		 * Get mesh local bounds.
+		 */
+		Bounds getBounds() const { return mBounds; }
+
+		/**
+		 * Set new internal buffers and a sub-mesh range.
+		 */
+		void updateData(const std::shared_ptr<VertexData>& vertexData, const IndexBufferPtr& indexBuffer, 
+			const SubMesh& subMesh, UINT32 vertexOffset);
+
+		/**
+		 * Get vertex buffers.
+		 */
+		std::shared_ptr<VertexData> getVertexData() const { return mVertexData; }
+
+		/**
+		 * Get index buffer.
+		 */
+		IndexBufferPtr getIndexBuffer() const { return mIndexBuffer; }
+
+		/**
+		 * Get sub-mesh range to render.
+		 */
+		SubMesh getSubMesh() const { return mSubMesh; }
+
+		/**
+		 * Get vertex offset;
+		 */
+		UINT32 getVertexOffset() const { return mVertexOffset; }
+
+		/**
+		 * Should be called by the renderer whenever the buffers get queued for use on the GPU.
+		 */
+		void notifyUsedOnGPU() const;
+
+	private:
+		friend class Mesh;
+
+		std::shared_ptr<VertexData> mVertexData;
+		IndexBufferPtr mIndexBuffer;
+		SubMesh mSubMesh;
+		UINT32 mVertexOffset;
+
+		Vector<RenderableSubProxy*> mRenderableProxies;
+		Bounds mBounds;
+		std::function<void()> mUsedOnGPUCallback;
+	};
+}