Browse Source

MeshProxy -> MeshRenderData and other minor changes

Marko Pintera 11 years ago
parent
commit
9218102124

+ 2 - 2
BansheeCore/BansheeCore.vcxproj

@@ -275,7 +275,7 @@
     <ClInclude Include="Include\BsCameraProxy.h" />
     <ClInclude Include="Include\BsCameraProxy.h" />
     <ClInclude Include="Include\BsDrawList.h" />
     <ClInclude Include="Include\BsDrawList.h" />
     <ClInclude Include="Include\BsMaterialProxy.h" />
     <ClInclude Include="Include\BsMaterialProxy.h" />
-    <ClInclude Include="Include\BsMeshProxy.h" />
+    <ClInclude Include="Include\BsMeshRenderData.h" />
     <ClInclude Include="Include\BsRenderableProxy.h" />
     <ClInclude Include="Include\BsRenderableProxy.h" />
     <ClInclude Include="Include\BsRenderStats.h" />
     <ClInclude Include="Include\BsRenderStats.h" />
     <ClInclude Include="Include\BsBindableGpuParamBlock.h" />
     <ClInclude Include="Include\BsBindableGpuParamBlock.h" />
@@ -426,7 +426,7 @@
     <ClCompile Include="Source\BsCameraProxy.cpp" />
     <ClCompile Include="Source\BsCameraProxy.cpp" />
     <ClCompile Include="Source\BsCoreThread.cpp" />
     <ClCompile Include="Source\BsCoreThread.cpp" />
     <ClCompile Include="Source\BsDrawList.cpp" />
     <ClCompile Include="Source\BsDrawList.cpp" />
-    <ClCompile Include="Source\BsMeshProxy.cpp" />
+    <ClCompile Include="Source\BsMeshRenderData.cpp" />
     <ClCompile Include="Source\BsProfilerCPU.cpp" />
     <ClCompile Include="Source\BsProfilerCPU.cpp" />
     <ClCompile Include="Source\BsDefaultRenderQueue.cpp" />
     <ClCompile Include="Source\BsDefaultRenderQueue.cpp" />
     <ClCompile Include="Source\BsDeferredCallManager.cpp" />
     <ClCompile Include="Source\BsDeferredCallManager.cpp" />

+ 3 - 3
BansheeCore/BansheeCore.vcxproj.filters

@@ -528,7 +528,7 @@
     <ClInclude Include="Include\BsDrawList.h">
     <ClInclude Include="Include\BsDrawList.h">
       <Filter>Header Files\Renderer</Filter>
       <Filter>Header Files\Renderer</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="Include\BsMeshProxy.h">
+    <ClInclude Include="Include\BsMeshRenderData.h">
       <Filter>Header Files\Renderer</Filter>
       <Filter>Header Files\Renderer</Filter>
     </ClInclude>
     </ClInclude>
   </ItemGroup>
   </ItemGroup>
@@ -836,10 +836,10 @@
     <ClCompile Include="Source\BsDrawList.cpp">
     <ClCompile Include="Source\BsDrawList.cpp">
       <Filter>Source Files\Renderer</Filter>
       <Filter>Source Files\Renderer</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="Source\BsMeshProxy.cpp">
+    <ClCompile Include="Source\BsCameraProxy.cpp">
       <Filter>Source Files\Renderer</Filter>
       <Filter>Source Files\Renderer</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="Source\BsCameraProxy.cpp">
+    <ClCompile Include="Source\BsMeshRenderData.cpp">
       <Filter>Source Files\Renderer</Filter>
       <Filter>Source Files\Renderer</Filter>
     </ClCompile>
     </ClCompile>
   </ItemGroup>
   </ItemGroup>

+ 1 - 1
BansheeCore/Include/BsCorePrerequisites.h

@@ -132,7 +132,7 @@ namespace BansheeEngine
 	class VideoModeInfo;
 	class VideoModeInfo;
 	class RenderableProxy;
 	class RenderableProxy;
 	class RenderableSubProxy;
 	class RenderableSubProxy;
-	class MeshProxy;
+	class MeshRenderData;
 	class CameraProxy;
 	class CameraProxy;
 	class MaterialProxy;
 	class MaterialProxy;
 	class DrawList;
 	class DrawList;

+ 9 - 9
BansheeCore/Include/BsGpuParams.h

@@ -44,15 +44,15 @@ namespace BansheeEngine
 		void setParamBlockBuffer(UINT32 slot, const GpuParamBlockBufferPtr& paramBlockBuffer);
 		void setParamBlockBuffer(UINT32 slot, const GpuParamBlockBufferPtr& paramBlockBuffer);
 
 
 		/**
 		/**
-		* @brief	Replaces the parameter buffer with the specified name. Any following parameter reads or
-		*			writes that are referencing that buffer will use the new buffer.
-		*
-		* @note		This is useful if you want to share a parameter buffer among multiple GPU programs.
-		*			You would only set the values once and then share the buffer among all other GpuParams.
-		*
-		*			It is up to the caller to guarantee the provided buffer matches parameter block
-		*			descriptor for this slot.
-		*/
+		 * @brief	Replaces the parameter buffer with the specified name. Any following parameter reads or
+		 *			writes that are referencing that buffer will use the new buffer.
+		 *
+		 * @note		This is useful if you want to share a parameter buffer among multiple GPU programs.
+		 *			You would only set the values once and then share the buffer among all other GpuParams.
+		 *
+		 *			It is up to the caller to guarantee the provided buffer matches parameter block
+		 *			descriptor for this slot.
+		 */
 		void setParamBlockBuffer(const String& name, const GpuParamBlockBufferPtr& paramBlockBuffer);
 		void setParamBlockBuffer(const String& name, const GpuParamBlockBufferPtr& paramBlockBuffer);
 
 
 		/**
 		/**

+ 4 - 4
BansheeCore/Include/BsMesh.h

@@ -2,7 +2,7 @@
 
 
 #include "BsCorePrerequisites.h"
 #include "BsCorePrerequisites.h"
 #include "BsMeshBase.h"
 #include "BsMeshBase.h"
-#include "BsMeshProxy.h"
+#include "BsMeshRenderData.h"
 #include "BsMeshData.h"
 #include "BsMeshData.h"
 #include "BsVertexData.h"
 #include "BsVertexData.h"
 #include "BsDrawOps.h"
 #include "BsDrawOps.h"
@@ -57,9 +57,9 @@ namespace BansheeEngine
 		virtual IndexBufferPtr _getIndexBuffer() const;
 		virtual IndexBufferPtr _getIndexBuffer() const;
 
 
 		/**
 		/**
-		 * @copydoc	MeshBase::_getMeshProxy
+		 * @copydoc	MeshBase::_getRenderData
 		 */
 		 */
-		MeshProxy& _getMeshProxy(UINT32 subMeshIdx) { return mMeshProxies[subMeshIdx]; }
+		MeshRenderData& _getRenderData(UINT32 subMeshIdx) { return mRenderData[subMeshIdx]; }
 
 
 		/**
 		/**
 		 * @brief	Returns a dummy mesh, containing just one triangle. Don't modify the returned mesh.
 		 * @brief	Returns a dummy mesh, containing just one triangle. Don't modify the returned mesh.
@@ -86,7 +86,7 @@ namespace BansheeEngine
 		IndexBufferPtr mIndexBuffer; // Core thread
 		IndexBufferPtr mIndexBuffer; // Core thread
 
 
 		Bounds mBounds; // Core thread
 		Bounds mBounds; // Core thread
-		Vector<MeshProxy> mMeshProxies; // Core thread
+		Vector<MeshRenderData> mRenderData; // Core thread
 
 
 		VertexDataDescPtr mVertexDesc; // Immutable
 		VertexDataDescPtr mVertexDesc; // Immutable
 		MeshBufferType mBufferType; // Immutable
 		MeshBufferType mBufferType; // Immutable

+ 4 - 7
BansheeCore/Include/BsMeshBase.h

@@ -126,15 +126,12 @@ namespace BansheeEngine
 		 */
 		 */
 		virtual void _notifyUsedOnGPU() { }
 		virtual void _notifyUsedOnGPU() { }
 
 
-		/************************************************************************/
-		/* 								PROXIES		                     		*/
-		/************************************************************************/
-
 		/**
 		/**
-		 * @brief	Gets mesh proxy object unique to this mesh. Each Mesh
-		 *			has one proxy. Mesh will update the proxy as changes to Mesh occur.
+		 * @brief	Gets sub-mesh render data. Render data provides a link between a mesh and
+		 *			the renderer and it will be modified by both. It may be modified as mesh 
+		 *			changes occur and as renderer uses the mesh.
 		 */
 		 */
-		virtual MeshProxy& _getMeshProxy(UINT32 subMeshIdx) = 0;
+		virtual MeshRenderData& _getRenderData(UINT32 subMeshIdx) = 0;
 
 
 	protected:
 	protected:
 		Vector<SubMesh> mSubMeshes; // Immutable
 		Vector<SubMesh> mSubMeshes; // Immutable

+ 0 - 42
BansheeCore/Include/BsMeshProxy.h

@@ -1,42 +0,0 @@
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsBounds.h"
-#include "BsSubMesh.h"
-
-namespace BansheeEngine
-{
-	/**
-	* Mesh proxy keeps a copy of Mesh data that is used by the Renderer. It
-	* also contains some Renderer specific data. Essentially it is a class that
-	* links Mesh and Renderer.
-	*/
-	// TODO UNDOCUMENTED
-	class BS_CORE_EXPORT MeshProxy
-	{
-	public:
-		MeshProxy() {}
-		MeshProxy(const std::shared_ptr<VertexData>& vertexData, const IndexBufferPtr& indexBuffer,
-			const SubMesh& subMesh);
-
-		void addRenderableProxy(RenderableSubProxy* proxy);
-		void removeRenderableProxy(RenderableSubProxy* proxy);
-
-		void updateBounds(const Bounds& bounds);
-		Bounds getBounds() const { return mBounds; }
-
-		void updateData(const std::shared_ptr<VertexData>& vertexData, const IndexBufferPtr& indexBuffer, const SubMesh& subMesh);
-
-		std::shared_ptr<VertexData> getVertexData() const { return mVertexData; }
-		IndexBufferPtr getIndexBuffer() const { return mIndexBuffer; }
-		SubMesh getSubMesh() const { return mSubMesh; }
-
-	private:
-		std::shared_ptr<VertexData> mVertexData;
-		IndexBufferPtr mIndexBuffer;
-		SubMesh mSubMesh;
-
-		Vector<RenderableSubProxy*> mRenderableProxies;
-		Bounds mBounds;
-	};
-}

+ 1 - 1
BansheeCore/Include/BsRenderOperation.h

@@ -17,7 +17,7 @@ namespace BansheeEngine
 		{ }
 		{ }
 
 
 		MaterialProxy material;
 		MaterialProxy material;
-		MeshProxy* mesh;
+		MeshRenderData* mesh;
 		Vector3 worldPosition;
 		Vector3 worldPosition;
 	};
 	};
 }
 }

+ 1 - 1
BansheeCore/Include/BsRenderQueue.h

@@ -32,7 +32,7 @@ namespace BansheeEngine
 	public:
 	public:
 		RenderQueue();
 		RenderQueue();
 
 
-		void add(const MaterialProxy& material, MeshProxy* mesh, const Vector3& worldPosForSort);
+		void add(const MaterialProxy& material, MeshRenderData* mesh, const Vector3& worldPosForSort);
 
 
 		/**
 		/**
 		 * @brief	Clears all render operations from the queue.
 		 * @brief	Clears all render operations from the queue.

+ 1 - 1
BansheeCore/Include/BsRenderableProxy.h

@@ -21,7 +21,7 @@ namespace BansheeEngine
 		UINT32 id;
 		UINT32 id;
 		Matrix4 worldTransform;
 		Matrix4 worldTransform;
 
 
-		MeshProxy* mesh;
+		MeshRenderData* mesh;
 		MaterialProxy material;
 		MaterialProxy material;
 
 
 		UINT64 layer;
 		UINT64 layer;

+ 6 - 6
BansheeCore/Include/BsTransientMesh.h

@@ -2,7 +2,7 @@
 
 
 #include "BsCorePrerequisites.h"
 #include "BsCorePrerequisites.h"
 #include "BsMeshBase.h"
 #include "BsMeshBase.h"
-#include "BsMeshProxy.h"
+#include "BsMeshRenderData.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
@@ -42,9 +42,9 @@ namespace BansheeEngine
 		IndexBufferPtr _getIndexBuffer() const;
 		IndexBufferPtr _getIndexBuffer() const;
 
 
 		/**
 		/**
-		 * @copydoc	MeshBase::_getMeshProxy
+		 * @copydoc	MeshBase::_getRenderData
 		 */
 		 */
-		MeshProxy& _getMeshProxy(UINT32 subMeshIdx) { return mMeshProxy; }
+		MeshRenderData& _getRenderData(UINT32 subMeshIdx) { return mRenderData; }
 
 
 		/**
 		/**
 		 * @brief	Returns the ID that uniquely identifies this mesh in the parent heap.
 		 * @brief	Returns the ID that uniquely identifies this mesh in the parent heap.
@@ -68,9 +68,9 @@ namespace BansheeEngine
 
 
 		/**
 		/**
 		 * @brief	Called by parent MeshHeap when notable changes that invalidate
 		 * @brief	Called by parent MeshHeap when notable changes that invalidate
-		 *			the mesh proxy happen.
+		 *			the render data happen.
 		 */
 		 */
-		void _updateProxy();
+		void _updateRenderData();
 
 
 	protected:
 	protected:
 		friend class MeshHeap;
 		friend class MeshHeap;
@@ -93,6 +93,6 @@ namespace BansheeEngine
 		MeshHeapPtr mParentHeap;
 		MeshHeapPtr mParentHeap;
 		UINT32 mId;
 		UINT32 mId;
 
 
-		MeshProxy mMeshProxy;
+		MeshRenderData mRenderData;
 	};
 	};
 }
 }

+ 3 - 3
BansheeCore/Source/BsMesh.cpp

@@ -171,8 +171,8 @@ namespace BansheeEngine
 
 
 			mBounds = calculateBounds((UINT8*)data, mTempInitialMeshData->getNumVertices(), stride);
 			mBounds = calculateBounds((UINT8*)data, mTempInitialMeshData->getNumVertices(), stride);
 
 
-			for (auto& proxy : mMeshProxies)
-				proxy.updateBounds(mBounds);
+			for (auto& renderData : mRenderData)
+				renderData.updateBounds(mBounds);
 
 
 			break;
 			break;
 		}
 		}
@@ -319,7 +319,7 @@ namespace BansheeEngine
 
 
 		for (auto& subMesh : mSubMeshes)
 		for (auto& subMesh : mSubMeshes)
 		{
 		{
-			mMeshProxies.push_back(MeshProxy(mVertexData, mIndexBuffer, subMesh));
+			mRenderData.push_back(MeshRenderData(mVertexData, mIndexBuffer, subMesh, 0, nullptr));
 
 
 		}
 		}
 
 

+ 2 - 2
BansheeCore/Source/BsMeshHeap.cpp

@@ -166,7 +166,7 @@ namespace BansheeEngine
 			for (auto& allocData : mMeshAllocData)
 			for (auto& allocData : mMeshAllocData)
 			{
 			{
 				if (allocData.second.useFlags != UseFlags::CPUFree && allocData.second.useFlags != UseFlags::Free)
 				if (allocData.second.useFlags != UseFlags::CPUFree && allocData.second.useFlags != UseFlags::Free)
-					allocData.second.mesh->_updateProxy();
+					allocData.second.mesh->_updateRenderData();
 			}
 			}
 		}
 		}
 
 
@@ -317,7 +317,7 @@ namespace BansheeEngine
 		memcpy(idxDest, meshData->getIndexData(), meshData->getNumIndices() * idxSize);
 		memcpy(idxDest, meshData->getIndexData(), meshData->getNumIndices() * idxSize);
 		mIndexBuffer->writeData(idxChunkStart * idxSize, meshData->getNumIndices() * idxSize, idxDest, BufferWriteType::NoOverwrite);
 		mIndexBuffer->writeData(idxChunkStart * idxSize, meshData->getNumIndices() * idxSize, idxDest, BufferWriteType::NoOverwrite);
 
 
-		mesh->_updateProxy();
+		mesh->_updateRenderData();
 	}
 	}
 
 
 	void MeshHeap::deallocInternal(TransientMeshPtr mesh)
 	void MeshHeap::deallocInternal(TransientMeshPtr mesh)

+ 0 - 42
BansheeCore/Source/BsMeshProxy.cpp

@@ -1,42 +0,0 @@
-#include "BsMeshProxy.h"
-#include "BsRenderableProxy.h"
-
-namespace BansheeEngine
-{
-	MeshProxy::MeshProxy(const std::shared_ptr<VertexData>& vertexData, 
-		const IndexBufferPtr& indexBuffer, const SubMesh& subMesh)
-		:mVertexData(vertexData), mIndexBuffer(indexBuffer), mSubMesh(subMesh)
-	{
-
-	}
-
-	void MeshProxy::addRenderableProxy(RenderableSubProxy* proxy)
-	{
-		mRenderableProxies.push_back(proxy);
-	}
-
-	void MeshProxy::removeRenderableProxy(RenderableSubProxy* proxy)
-	{
-		auto iterFind = std::find(mRenderableProxies.begin(), mRenderableProxies.end(), proxy);
-
-		if (iterFind != mRenderableProxies.end())
-			mRenderableProxies.erase(iterFind);
-	}
-
-	void MeshProxy::updateBounds(const Bounds& bounds)
-	{
-		mBounds = bounds;
-
-		for (auto& renderableProxy : mRenderableProxies)
-		{
-			renderableProxy->markBoundsDirty();
-		}
-	}
-
-	void MeshProxy::updateData(const std::shared_ptr<VertexData>& vertexData, const IndexBufferPtr& indexBuffer, const SubMesh& subMesh)
-	{
-		mVertexData = vertexData;
-		mIndexBuffer = indexBuffer;
-		mSubMesh = subMesh;
-	}
-}

+ 50 - 0
BansheeCore/Source/BsMeshRenderData.cpp

@@ -0,0 +1,50 @@
+#include "BsMeshRenderData.h"
+#include "BsRenderableProxy.h"
+
+namespace BansheeEngine
+{
+	MeshRenderData::MeshRenderData(const std::shared_ptr<VertexData>& vertexData, 
+		const IndexBufferPtr& indexBuffer, const SubMesh& subMesh, UINT32 vertexOffset, std::function<void()> usedOnGPUcallback)
+		:mVertexData(vertexData), mIndexBuffer(indexBuffer), mSubMesh(subMesh), 
+		mUsedOnGPUCallback(usedOnGPUcallback), mVertexOffset(vertexOffset)
+	{
+
+	}
+
+	void MeshRenderData::addRenderableProxy(RenderableSubProxy* proxy)
+	{
+		mRenderableProxies.push_back(proxy);
+	}
+
+	void MeshRenderData::removeRenderableProxy(RenderableSubProxy* proxy)
+	{
+		auto iterFind = std::find(mRenderableProxies.begin(), mRenderableProxies.end(), proxy);
+
+		if (iterFind != mRenderableProxies.end())
+			mRenderableProxies.erase(iterFind);
+	}
+
+	void MeshRenderData::updateBounds(const Bounds& bounds)
+	{
+		mBounds = bounds;
+
+		for (auto& renderableProxy : mRenderableProxies)
+		{
+			renderableProxy->markBoundsDirty();
+		}
+	}
+
+	void MeshRenderData::updateData(const std::shared_ptr<VertexData>& vertexData, const IndexBufferPtr& indexBuffer, 
+		const SubMesh& subMesh, UINT32 vertexOffset)
+	{
+		mVertexData = vertexData;
+		mIndexBuffer = indexBuffer;
+		mSubMesh = subMesh;
+	}
+
+	void MeshRenderData::notifyUsedOnGPU() const
+	{
+		if (mUsedOnGPUCallback != nullptr)
+			mUsedOnGPUCallback();
+	}
+}

+ 1 - 1
BansheeCore/Source/BsRenderQueue.cpp

@@ -14,7 +14,7 @@ namespace BansheeEngine
 		mSortedRenderOps.clear();
 		mSortedRenderOps.clear();
 	}
 	}
 
 
-	void RenderQueue::add(const MaterialProxy& material, MeshProxy* mesh, const Vector3& worldPosForSort)
+	void RenderQueue::add(const MaterialProxy& material, MeshRenderData* mesh, const Vector3& worldPosForSort)
 	{
 	{
 		// TODO - Make sure RenderOperations are cached so we dont allocate memory for them every frame
 		// TODO - Make sure RenderOperations are cached so we dont allocate memory for them every frame
 		mRenderOperations.push_back(RenderOperation());
 		mRenderOperations.push_back(RenderOperation());

+ 1 - 1
BansheeCore/Source/BsRenderableProxy.cpp

@@ -1,5 +1,5 @@
 #include "BsRenderableProxy.h"
 #include "BsRenderableProxy.h"
-#include "BsMeshProxy.h"
+#include "BsMeshRenderData.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {

+ 5 - 4
BansheeCore/Source/BsTransientMesh.cpp

@@ -7,7 +7,7 @@ namespace BansheeEngine
 	TransientMesh::TransientMesh(const MeshHeapPtr& parentHeap, UINT32 id, UINT32 numVertices, UINT32 numIndices, DrawOperationType drawOp)
 	TransientMesh::TransientMesh(const MeshHeapPtr& parentHeap, UINT32 id, UINT32 numVertices, UINT32 numIndices, DrawOperationType drawOp)
 		:MeshBase(numVertices, numIndices, drawOp), mParentHeap(parentHeap), mId(id), mIsDestroyed(false)
 		:MeshBase(numVertices, numIndices, drawOp), mParentHeap(parentHeap), mId(id), mIsDestroyed(false)
 	{
 	{
-
+		mRenderData = MeshRenderData(nullptr, nullptr, SubMesh(), 0, std::bind(&TransientMesh::_notifyUsedOnGPU, this));
 	}
 	}
 
 
 	TransientMesh::~TransientMesh()
 	TransientMesh::~TransientMesh()
@@ -54,9 +54,10 @@ namespace BansheeEngine
 		mParentHeap->notifyUsedOnGPU(mId);
 		mParentHeap->notifyUsedOnGPU(mId);
 	}
 	}
 
 
-	void TransientMesh::_updateProxy()
+	void TransientMesh::_updateRenderData()
 	{
 	{
-		mMeshProxy.updateData(mParentHeap->_getVertexData(), mParentHeap->_getIndexBuffer(),
-			SubMesh(mParentHeap->getIndexOffset(mId), getNumIndices(), getSubMesh(0).drawOp));
+		mRenderData.updateData(mParentHeap->_getVertexData(), mParentHeap->_getIndexBuffer(),
+			SubMesh(mParentHeap->getIndexOffset(mId), getNumIndices(), getSubMesh(0).drawOp),
+			mParentHeap->getVertexOffset(mId));
 	}
 	}
 }
 }

+ 3 - 2
BansheeEngine/Include/BsCamera.h

@@ -307,6 +307,9 @@ namespace BansheeEngine
 		 */
 		 */
 		void setLayers(UINT64 layers) { mLayers = layers; }
 		void setLayers(UINT64 layers) { mLayers = layers; }
 
 
+		// TODO UNDOCUMENTED
+		CameraProxy _createProxy() const;
+
         static const float INFINITE_FAR_PLANE_ADJUST; /**< Small constant used to reduce far plane projection to avoid inaccuracies. */
         static const float INFINITE_FAR_PLANE_ADJUST; /**< Small constant used to reduce far plane projection to avoid inaccuracies. */
 
 
 	protected:
 	protected:
@@ -370,8 +373,6 @@ namespace BansheeEngine
 		mutable float mLeft, mRight, mTop, mBottom; /**< Frustum extents. */
 		mutable float mLeft, mRight, mTop, mBottom; /**< Frustum extents. */
 		mutable AABox mBoundingBox; /**< Frustum bounding box. */
 		mutable AABox mBoundingBox; /**< Frustum bounding box. */
 
 
-		CameraProxy _createProxy() const;
-
 		/************************************************************************/
 		/************************************************************************/
 		/* 						COMPONENT OVERRIDES                      		*/
 		/* 						COMPONENT OVERRIDES                      		*/
 		/************************************************************************/
 		/************************************************************************/

+ 2 - 2
BansheeEngine/Include/BsRenderable.h

@@ -73,13 +73,13 @@ namespace BansheeEngine
 		 * @brief	Return the number of materials used by the renderable. Each material
 		 * @brief	Return the number of materials used by the renderable. Each material
 		 *			will be used for rendering a sub-mesh in the provided Mesh.
 		 *			will be used for rendering a sub-mesh in the provided Mesh.
 		 */
 		 */
-		UINT32 getNumMaterials() const { return (UINT32)mMaterials.size(); }
+		UINT32 getNumMaterials() const { return (UINT32)mMaterialData.size(); }
 
 
 		/**
 		/**
 		 * @brief	Returns the material used for rendering a sub-mesh with
 		 * @brief	Returns the material used for rendering a sub-mesh with
 		 *			the specified index.
 		 *			the specified index.
 		 */
 		 */
-		HMaterial& getMaterial(UINT32 idx) { return mMaterials[idx]; }
+		HMaterial& getMaterial(UINT32 idx) { return mMaterialData[idx].material; }
 
 
 		// TODO UNDOCUMENTED
 		// TODO UNDOCUMENTED
 		bool _isRenderDataDirty() const;
 		bool _isRenderDataDirty() const;

+ 1 - 1
BansheeEngine/Source/BsGUIManager.cpp

@@ -178,7 +178,7 @@ namespace BansheeEngine
 
 
 	void GUIManager::update()
 	void GUIManager::update()
 	{
 	{
-		DragAndDropManager::instance().update();
+		DragAndDropManager::instance()._update();
 
 
 		// Update layouts
 		// Update layouts
 		gProfilerCPU().beginSample("UpdateLayout");
 		gProfilerCPU().beginSample("UpdateLayout");

+ 1 - 1
BansheeEngine/Source/BsRenderable.cpp

@@ -104,7 +104,7 @@ namespace BansheeEngine
 			RenderableSubProxy* subProxy = bs_new<RenderableSubProxy>();
 			RenderableSubProxy* subProxy = bs_new<RenderableSubProxy>();
 			subProxy->layer = mLayer;
 			subProxy->layer = mLayer;
 			subProxy->worldTransform = SO()->getWorldTfrm();
 			subProxy->worldTransform = SO()->getWorldTfrm();
-			subProxy->mesh = &mMeshData.mesh->_getMeshProxy(i);
+			subProxy->mesh = &mMeshData.mesh->_getRenderData(i);
 
 
 			HMaterial material;
 			HMaterial material;
 			if (i < mMaterialData.size())
 			if (i < mMaterialData.size())

+ 1 - 0
BansheeRenderer/Include/BsBansheeRenderer.h

@@ -60,6 +60,7 @@ namespace BansheeEngine
 		virtual void render(const CameraProxy& cameraProxy, const RenderQueuePtr& renderQueue);
 		virtual void render(const CameraProxy& cameraProxy, const RenderQueuePtr& renderQueue);
 
 
 		void setPass(const MaterialProxy::PassData& pass);
 		void setPass(const MaterialProxy::PassData& pass);
+		void draw(const MeshRenderData& mesh);
 
 
 		void renderableRemoved(const HRenderable& renderable);
 		void renderableRemoved(const HRenderable& renderable);
 
 

+ 56 - 7
BansheeRenderer/Source/BsBansheeRenderer.cpp

@@ -225,7 +225,7 @@ namespace BansheeEngine
 				// TODO - Will I need to check if materials match renderer?
 				// TODO - Will I need to check if materials match renderer?
 
 
 				renderQueue->add(drawOp.material->_createProxy(gCoreThread().getFrameAlloc()),
 				renderQueue->add(drawOp.material->_createProxy(gCoreThread().getFrameAlloc()),
-					&drawOp.mesh->_getMeshProxy(drawOp.submeshIdx), drawOp.worldPosition);
+					&drawOp.mesh->_getRenderData(drawOp.submeshIdx), drawOp.worldPosition);
 			}
 			}
 
 
 			idx++;
 			idx++;
@@ -236,6 +236,8 @@ namespace BansheeEngine
 
 
 	void BansheeRenderer::renderAllCore(std::shared_ptr<FrameData> frameData)
 	void BansheeRenderer::renderAllCore(std::shared_ptr<FrameData> frameData)
 	{
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		// Render everything, target by target
 		// Render everything, target by target
 		for (auto& renderTargetData : frameData->renderTargets)
 		for (auto& renderTargetData : frameData->renderTargets)
 		{
 		{
@@ -272,6 +274,8 @@ namespace BansheeEngine
 
 
 	void BansheeRenderer::render(const CameraProxy& cameraProxy, const RenderQueuePtr& renderQueue) 
 	void BansheeRenderer::render(const CameraProxy& cameraProxy, const RenderQueuePtr& renderQueue) 
 	{
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		RenderSystem& rs = RenderSystem::instance();
 		RenderSystem& rs = RenderSystem::instance();
 
 
 		if (!cameraProxy.ignoreSceneRenderables)
 		if (!cameraProxy.ignoreSceneRenderables)
@@ -300,17 +304,14 @@ namespace BansheeEngine
 			const MaterialProxy& materialProxy = renderOp.material;
 			const MaterialProxy& materialProxy = renderOp.material;
 
 
 			setPass(materialProxy.passes[iter->passIdx]);
 			setPass(materialProxy.passes[iter->passIdx]);
-
-			// TODO - Call rs.render() - I need to refactor it so it accepts vertex and index data instead of mesh,
-			// but I need to find a way to notify mesh when it is used on GPU. (Notify the proxy?)
-
-			SubMesh subMesh = renderOp.mesh->getSubMesh();
-			//rs.render(renderOp.mesh->getVertexData(), renderOp.mesh->getIndexBuffer(), subMesh.indexOffset, subMesh.indexCount, true, subMesh.drawOp);
+			draw(*renderOp.mesh);
 		}
 		}
 	}
 	}
 
 
 	void BansheeRenderer::setPass(const MaterialProxy::PassData& pass)
 	void BansheeRenderer::setPass(const MaterialProxy::PassData& pass)
 	{
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		RenderSystem& rs = RenderSystem::instance();
 		RenderSystem& rs = RenderSystem::instance();
 
 
 		if (pass.vertexProg)
 		if (pass.vertexProg)
@@ -379,4 +380,52 @@ namespace BansheeEngine
 		else
 		else
 			rs.setRasterizerState(RasterizerState::getDefault());
 			rs.setRasterizerState(RasterizerState::getDefault());
 	}
 	}
+
+	void BansheeRenderer::draw(const MeshRenderData& mesh)
+	{
+		THROW_IF_NOT_CORE_THREAD;
+
+		RenderSystem& rs = RenderSystem::instance();
+		std::shared_ptr<VertexData> vertexData = mesh.getVertexData();
+
+		rs.setVertexDeclaration(vertexData->vertexDeclaration);
+		auto vertexBuffers = vertexData->getBuffers();
+
+		if (vertexBuffers.size() > 0)
+		{
+			VertexBufferPtr buffers[MAX_BOUND_VERTEX_BUFFERS];
+
+			UINT32 endSlot = 0;
+			UINT32 startSlot = MAX_BOUND_VERTEX_BUFFERS;
+			for (auto iter = vertexBuffers.begin(); iter != vertexBuffers.end(); ++iter)
+			{
+				if (iter->first >= MAX_BOUND_VERTEX_BUFFERS)
+					BS_EXCEPT(InvalidParametersException, "Buffer index out of range");
+
+				startSlot = std::min(iter->first, startSlot);
+				endSlot = std::max(iter->first, endSlot);
+			}
+
+			for (auto iter = vertexBuffers.begin(); iter != vertexBuffers.end(); ++iter)
+			{
+				buffers[iter->first - startSlot] = iter->second;
+			}
+
+			rs.setVertexBuffers(startSlot, buffers, endSlot - startSlot + 1);
+		}
+
+		SubMesh subMesh = mesh.getSubMesh();
+		rs.setDrawOperation(subMesh.drawOp);
+
+		IndexBufferPtr indexBuffer = mesh.getIndexBuffer();
+
+		UINT32 indexCount = subMesh.indexCount;
+		if (indexCount == 0)
+			indexCount = indexBuffer->getNumIndices();
+
+		rs.setIndexBuffer(indexBuffer);
+		rs.drawIndexed(subMesh.indexOffset, indexCount, mesh.getVertexOffset(), vertexData->vertexCount);
+
+		mesh.notifyUsedOnGPU();
+	}
 }
 }

+ 39 - 4
Renderer.txt

@@ -1,7 +1,21 @@
-To get it to compile:
- - Add dummy material that will be used when material is not loaded
- - Actually implement core render methods in Renderer
- - Go through all changes on commit and see if anything else needs doing
+Get renderer to run
+ - Go through TODOs on BansheeRenderer
+ - What happens to MeshRenderData when mesh is destroyed? It contains a callback to Mesh, so I must ensure it outlives it.
+ - How to clean up RenderableProxies in Renderer?
+ - Even though I allocate material proxies with frame alloc I think I still need to free them for debug purposes
+
+What happens when technique/shader changes?
+ - Have isProxyDirty flag in Material. Renderable checks that flag and returns dirty for the Renderable when toggled (and cleans the flag).
+   Then we just create a new Material proxy. When new material proxy is created a copy of all current GpuParams is created.
+
+What happens when gpu prog param buffer changes?
+ - Material has another flag areParamsDirty (actally GpuParams should have that flag). If true I call
+   updateMaterialProxy() with wanted pass, gpu prog idx and BindableGpuParams. BindableGpuParams are then used
+   for copying new data to core thread GpuParams.
+
+What happens when a parameter is updated?
+ - Same as above. Make sure not to send updates if shared or renderer param block was updated.
+
 
 
 Next stage:
 Next stage:
  - Track material changes
  - Track material changes
@@ -20,6 +34,13 @@ Finally
  - Get rid of Camera::getIgnoreSceneRenderables it can be doing using layers
  - Get rid of Camera::getIgnoreSceneRenderables it can be doing using layers
  - Delete RenderOperation as I don't think I use it anymore
  - Delete RenderOperation as I don't think I use it anymore
 
 
+Semantic/design issues:
+ - DrawList is too similar to RenderQueue - Their names need to be more distinct
+ - MeshProxy is very different that material/camera/renderable proxy. Rename it to something else?
+ - Material and camera proxy is returned by value while renderable by pointer. Also material proxy seems a bit heavy weight to be passed by value.
+ - Consider removing SceneManager from Core? I two scene manager base classes.
+ - Consider moving RenderOperation in RenderQueue and removing its header/source. Maybe also renaming it to something more render queue specific. 
+ - Remove DefaultRenderQueue. Instead make RenderQueue non-abstract and have it provide default implementation.
 
 
 -----------------------------------------
 -----------------------------------------
 
 
@@ -44,6 +65,20 @@ When a Material is hooked up to a Renderable is will check if the Material has t
    are for the renderer. (And so that Material knows not to create those buffers manually)
    are for the renderer. (And so that Material knows not to create those buffers manually)
 
 
 
 
+when calling addParameter add an argument "rendererSemantic" - 0 means its a custom parameter, and the rest are enum values 
+provided by the renderer. (Actually an UINT32 so it may be extended). When render proxy is being created I compare those parameters 
+and ensure they match. If they don't match I use a dummy material.
+
+you can so something similar to parameter blocks - also provide a semantic to determine if its renderer one time, per frame,
+ per object, etc. If shader has such a block AND the gpu program desc actually has a parameter block then this will also be 
+ checked for validity when when creating a proxy (actually it might be better to check validity any time material or renderable options 
+ change and then just cache it). Param block and its members must exactly match (type AND order).
+
+Material DOES NOT automatically create param blocks with renderer semantic
+
+
+
+
    ---------------------------
    ---------------------------
 
 
 Just notes for later potentially:
 Just notes for later potentially: