Marko Pintera 13 лет назад
Родитель
Сommit
323608b2b8
28 измененных файлов с 724 добавлено и 24 удалено
  1. 12 4
      CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj
  2. 24 0
      CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj.filters
  3. 1 1
      CamelotD3D11RenderSystem/Include/CmD3D11Device.h
  4. 1 1
      CamelotD3D11RenderSystem/Include/CmD3D11Driver.h
  5. 8 8
      CamelotD3D11RenderSystem/Include/CmD3D11HLSLProgram.h
  6. 49 0
      CamelotD3D11RenderSystem/Include/CmD3D11HardwareBuffer.h
  7. 50 0
      CamelotD3D11RenderSystem/Include/CmD3D11HardwareConstantBuffer.h
  8. 50 0
      CamelotD3D11RenderSystem/Include/CmD3D11HardwareIndexBuffer.h
  9. 50 0
      CamelotD3D11RenderSystem/Include/CmD3D11HardwareVertexBuffer.h
  10. 2 1
      CamelotD3D11RenderSystem/Include/CmD3D11Mappings.h
  11. 1 0
      CamelotD3D11RenderSystem/Include/CmD3D11Prerequisites.h
  12. 1 0
      CamelotD3D11RenderSystem/Include/CmD3D11VideoModeList.h
  13. 2 2
      CamelotD3D11RenderSystem/Source/CmD3D11Device.cpp
  14. 2 0
      CamelotD3D11RenderSystem/Source/CmD3D11HLSLProgram.cpp
  15. 256 0
      CamelotD3D11RenderSystem/Source/CmD3D11HardwareBuffer.cpp
  16. 42 0
      CamelotD3D11RenderSystem/Source/CmD3D11HardwareConstantBuffer.cpp
  17. 42 0
      CamelotD3D11RenderSystem/Source/CmD3D11HardwareIndexBuffer.cpp
  18. 42 0
      CamelotD3D11RenderSystem/Source/CmD3D11HardwareVertexBuffer.cpp
  19. 17 0
      CamelotD3D11RenderSystem/Source/CmD3D11Mappings.cpp
  20. 1 2
      CamelotD3D11RenderSystem/Source/CmD3D11VideoModeList.cpp
  21. 2 0
      CamelotRenderer/CamelotRenderer.vcxproj
  22. 6 0
      CamelotRenderer/CamelotRenderer.vcxproj.filters
  23. 1 3
      CamelotRenderer/Include/CmHardwareBuffer.h
  24. 6 2
      CamelotRenderer/Include/CmHardwareBufferManager.h
  25. 21 0
      CamelotRenderer/Include/CmHardwareConstantBuffer.h
  26. 2 0
      CamelotRenderer/Include/CmPrerequisites.h
  27. 13 0
      CamelotRenderer/Source/CmHardwareBufferManager.cpp
  28. 20 0
      CamelotRenderer/Source/CmHardwareConstantBuffer.cpp

+ 12 - 4
CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj

@@ -90,7 +90,7 @@
     </ClCompile>
     <Link>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>CamelotRenderer.lib;CamelotUtility.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>D3DCompiler.lib;CamelotRenderer.lib;CamelotUtility.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86;..\lib\$(Configuration);..\Dependencies\lib\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <ImportLibrary>..\lib\$(Configuration)\$(TargetName).lib</ImportLibrary>
     </Link>
@@ -104,7 +104,7 @@
     </ClCompile>
     <Link>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>CamelotRenderer.lib;CamelotUtility.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>D3DCompiler.lib;CamelotRenderer.lib;CamelotUtility.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x64;..\lib\$(Platform)\$(Configuration);..\Dependencies\lib\x64\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <ImportLibrary>..\lib\$(Platform)\$(Configuration)\$(TargetName).lib</ImportLibrary>
     </Link>
@@ -122,7 +122,7 @@
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>CamelotRenderer.lib;CamelotUtility.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>D3DCompiler.lib;CamelotRenderer.lib;CamelotUtility.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86;..\lib\$(Configuration);..\Dependencies\lib\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <ImportLibrary>..\lib\$(Configuration)\$(TargetName).lib</ImportLibrary>
     </Link>
@@ -140,20 +140,24 @@
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>CamelotRenderer.lib;CamelotUtility.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>D3DCompiler.lib;CamelotRenderer.lib;CamelotUtility.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x64;..\lib\$(Platform)\$(Configuration);..\Dependencies\lib\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <ImportLibrary>..\lib\$(Platform)\$(Configuration)\$(TargetName).lib</ImportLibrary>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClInclude Include="Include\CmD3D11HardwareConstantBuffer.h" />
     <ClInclude Include="Include\CmD3D11Device.h" />
     <ClInclude Include="Include\CmD3D11Driver.h" />
     <ClInclude Include="Include\CmD3D11DriverList.h" />
     <ClInclude Include="Include\CmD3D11GpuProgram.h" />
     <ClInclude Include="Include\CmD3D11GpuProgramManager.h" />
+    <ClInclude Include="Include\CmD3D11HardwareBuffer.h" />
     <ClInclude Include="Include\CmD3D11HLSLProgram.h" />
+    <ClInclude Include="Include\CmD3D11HardwareIndexBuffer.h" />
     <ClInclude Include="Include\CmD3D11Mappings.h" />
     <ClInclude Include="Include\CmD3D11Prerequisites.h" />
+    <ClInclude Include="Include\CmD3D11HardwareVertexBuffer.h" />
     <ClInclude Include="Include\CmD3D11VideoMode.h" />
     <ClInclude Include="Include\CmD3D11VideoModeList.h" />
   </ItemGroup>
@@ -163,8 +167,12 @@
     <ClCompile Include="Source\CmD3D11DriverList.cpp" />
     <ClCompile Include="Source\CmD3D11GpuProgram.cpp" />
     <ClCompile Include="Source\CmD3D11GpuProgramManager.cpp" />
+    <ClCompile Include="Source\CmD3D11HardwareBuffer.cpp" />
+    <ClCompile Include="Source\CmD3D11HardwareConstantBuffer.cpp" />
     <ClCompile Include="Source\CmD3D11HLSLProgram.cpp" />
+    <ClCompile Include="Source\CmD3D11HardwareIndexBuffer.cpp" />
     <ClCompile Include="Source\CmD3D11Mappings.cpp" />
+    <ClCompile Include="Source\CmD3D11HardwareVertexBuffer.cpp" />
     <ClCompile Include="Source\CmD3D11VideoMode.cpp" />
     <ClCompile Include="Source\CmD3D11VideoModeList.cpp" />
   </ItemGroup>

+ 24 - 0
CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj.filters

@@ -45,6 +45,18 @@
     <ClInclude Include="Include\CmD3D11HLSLProgram.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\CmD3D11HardwareBuffer.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\CmD3D11HardwareIndexBuffer.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\CmD3D11HardwareVertexBuffer.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\CmD3D11HardwareConstantBuffer.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CmD3D11GpuProgram.cpp">
@@ -74,5 +86,17 @@
     <ClCompile Include="Source\CmD3D11HLSLProgram.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\CmD3D11HardwareBuffer.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\CmD3D11HardwareIndexBuffer.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\CmD3D11HardwareVertexBuffer.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\CmD3D11HardwareConstantBuffer.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11Device.h

@@ -19,7 +19,7 @@ namespace CamelotEngine
 		/**
 		 * @brief	Resets error state & error messages.
 		 */
-		void clearError();
+		void clearErrors();
 
 		/**
 		 * @brief	Query if error occurred at any point since class "clearError" call.

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11Driver.h

@@ -31,6 +31,6 @@ namespace CamelotEngine
 		D3D11VideoModeList**	mVideoModeList;
 		IDXGIAdapter*			mDXGIAdapter;
 
-		void init()
+		void init();
 	};
 }

+ 8 - 8
CamelotD3D11RenderSystem/Include/CmD3D11HLSLProgram.h

@@ -28,14 +28,14 @@ namespace CamelotEngine
 		D3D11HLSLProgram(const String& source, const String& entryPoint, const String& language, 
 			GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired = false);
 
-        /** Internal load implementation, must be implemented by subclasses.
-        */
-        void loadFromSource(void);
-        /** Internal method for creating an appropriate low-level program from this
-        high-level program, must be implemented by subclasses. */
-        void createLowLevelImpl(void);
-        /// Internal unload implementation, must be implemented by subclasses
-        void unloadHighLevelImpl(void);
+        ///** Internal load implementation, must be implemented by subclasses.
+        //*/
+        //void loadFromSource(void);
+        ///** Internal method for creating an appropriate low-level program from this
+        //high-level program, must be implemented by subclasses. */
+        //void createLowLevelImpl(void);
+        ///// Internal unload implementation, must be implemented by subclasses
+        //void unloadHighLevelImpl(void);
 
 		ID3DBlob* compileMicrocode();
 

+ 49 - 0
CamelotD3D11RenderSystem/Include/CmD3D11HardwareBuffer.h

@@ -0,0 +1,49 @@
+#pragma once
+
+#include "CmD3D11Prerequisites.h"
+#include "CmHardwareBuffer.h"
+
+namespace CamelotEngine
+{
+	class CM_D3D11_EXPORT D3D11HardwareBuffer : public HardwareBuffer
+	{
+	public:
+		enum BufferType
+		{
+			VERTEX_BUFFER,
+			INDEX_BUFFER,
+			CONSTANT_BUFFER
+		};
+
+	protected:
+		ID3D11Buffer* mD3DBuffer;
+		bool mUseTempStagingBuffer;
+		D3D11HardwareBuffer* mpTempStagingBuffer;
+		bool mStagingUploadNeeded;
+		BufferType mBufferType;
+		D3D11Device& mDevice;
+		D3D11_BUFFER_DESC mDesc;
+
+		/** See HardwareBuffer. */
+		void* lockImpl(UINT32 offset, UINT32 length, LockOptions options);
+		/** See HardwareBuffer. */
+		void unlockImpl(void);
+
+	public:
+		D3D11HardwareBuffer(BufferType btype, UINT32 sizeBytes, HardwareBuffer::Usage usage, 
+			D3D11Device& device, bool useSystemMem, bool streamOut);
+		~D3D11HardwareBuffer();
+
+		/** See HardwareBuffer. */
+		void readData(UINT32 offset, UINT32 length, void* pDest);
+		/** See HardwareBuffer. */
+		void writeData(UINT32 offset, UINT32 length, const void* pSource,
+			bool discardWholeBuffer = false);
+		/** See HardwareBuffer. We perform a hardware copy here. */
+		void copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, 
+			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
+
+		/// Get the D3D-specific buffer
+		ID3D11Buffer* getD3DBuffer(void) { return mD3DBuffer; }
+	};
+}

+ 50 - 0
CamelotD3D11RenderSystem/Include/CmD3D11HardwareConstantBuffer.h

@@ -0,0 +1,50 @@
+#pragma once
+
+#include "CmD3D11Prerequisites.h"
+#include "CmHardwareConstantBuffer.h"
+#include "CmD3D11HardwareBuffer.h"
+
+namespace CamelotEngine
+{
+	class CM_D3D11_EXPORT D3D11HardwareConstantBuffer : public HardwareConstantBuffer
+	{
+	public:
+		D3D11HardwareConstantBuffer(D3D11Device& device, HardwareBufferManagerBase* mgr, UINT32 sizeBytes, 
+			HardwareBuffer::Usage usage, bool useSystemMem);
+		~D3D11HardwareConstantBuffer();
+
+		/**
+		 * @copydoc HardwareBuffer::readData
+		 */
+		void readData(UINT32 offset, UINT32 length, void* pDest);
+
+		/**
+		 * @copydoc HardwareBuffer::writeData
+		 */
+		void writeData(UINT32 offset, UINT32 length, const void* pSource,
+			bool discardWholeBuffer = false);
+
+		/**
+		 * @copydoc HardwareBuffer::copyData
+		 */
+		void copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
+
+		/**
+		 * @brief	Get the D3D-specific index buffer
+		 */
+		ID3D11Buffer* getD3DConstantBuffer() const { return mBuffer->getD3DBuffer(); }		
+
+	protected:
+		/**
+		* @copydoc HardwareBuffer::lockImpl
+		 */
+		void* lockImpl(UINT32 offset, UINT32 length, LockOptions options);
+
+		/**
+		 * @copydoc HardwareBuffer::unlockImpl
+		 */
+		void unlockImpl(void);
+
+		D3D11HardwareBuffer* mBuffer;
+	};
+}

+ 50 - 0
CamelotD3D11RenderSystem/Include/CmD3D11HardwareIndexBuffer.h

@@ -0,0 +1,50 @@
+#pragma once
+
+#include "CmD3D11Prerequisites.h"
+#include "CmHardwareIndexBuffer.h"
+#include "CmD3D11HardwareBuffer.h"
+
+namespace CamelotEngine
+{
+	class CM_D3D11_EXPORT D3D11HardwareIndexBuffer : public HardwareIndexBuffer
+	{
+	public:
+		D3D11HardwareIndexBuffer(D3D11Device& device, HardwareBufferManagerBase* mgr, IndexType idxType, UINT32 numIndexes, 
+			HardwareBuffer::Usage usage, bool useSystemMem);
+		~D3D11HardwareIndexBuffer();
+
+		/**
+		 * @copydoc HardwareBuffer::readData
+		 */
+		void readData(UINT32 offset, UINT32 length, void* pDest);
+
+		/**
+		 * @copydoc HardwareBuffer::writeData
+		 */
+		void writeData(UINT32 offset, UINT32 length, const void* pSource,
+			bool discardWholeBuffer = false);
+
+		/**
+		 * @copydoc HardwareBuffer::copyData
+		 */
+		void copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
+
+		/**
+		 * @brief	Get the D3D-specific index buffer
+		 */
+		ID3D11Buffer* getD3DIndexBuffer() const { return mBuffer->getD3DBuffer(); }		
+
+	protected:
+		/**
+		* @copydoc HardwareBuffer::lockImpl
+		 */
+		void* lockImpl(UINT32 offset, UINT32 length, LockOptions options);
+
+		/**
+		 * @copydoc HardwareBuffer::unlockImpl
+		 */
+		void unlockImpl(void);
+
+		D3D11HardwareBuffer* mBuffer;
+	};
+}

+ 50 - 0
CamelotD3D11RenderSystem/Include/CmD3D11HardwareVertexBuffer.h

@@ -0,0 +1,50 @@
+#pragma once
+
+#include "CmD3D11Prerequisites.h"
+#include "CmHardwareVertexBuffer.h"
+#include "CmD3D11HardwareBuffer.h"
+
+namespace CamelotEngine
+{
+	class CM_D3D11_EXPORT D3D11HardwareVertexBuffer : public HardwareVertexBuffer
+	{
+	public:
+		D3D11HardwareVertexBuffer(D3D11Device& device, HardwareBufferManagerBase* mgr, UINT32 vertexSize, UINT32 numVertices, 
+			HardwareBuffer::Usage usage, bool useSystemMem);
+		~D3D11HardwareVertexBuffer();
+
+		/**
+		 * @copydoc HardwareBuffer::readData
+		 */
+		void readData(UINT32 offset, UINT32 length, void* pDest);
+
+		/**
+		 * @copydoc HardwareBuffer::writeData
+		 */
+		void writeData(UINT32 offset, UINT32 length, const void* pSource,
+			bool discardWholeBuffer = false);
+
+		/**
+		 * @copydoc HardwareBuffer::copyData
+		 */
+		void copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
+
+		/**
+		 * @brief	Get the D3D-specific index buffer
+		 */
+		ID3D11Buffer* getD3DVertexBuffer() const { return mBuffer->getD3DBuffer(); }		
+
+	protected:
+		/**
+		* @copydoc HardwareBuffer::lockImpl
+		 */
+		void* lockImpl(UINT32 offset, UINT32 length, LockOptions options);
+
+		/**
+		 * @copydoc HardwareBuffer::unlockImpl
+		 */
+		void unlockImpl(void);
+
+		D3D11HardwareBuffer* mBuffer;
+	};
+}

+ 2 - 1
CamelotD3D11RenderSystem/Include/CmD3D11Mappings.h

@@ -54,7 +54,8 @@ namespace CamelotEngine
 		static VertexElementSemantic get(LPCSTR sem);
 		/// Get dx11 color
 		static void get(const Color& inColour, float * outColour );
-
+		static bool isMappingWrite(D3D11_MAP map);
+		static bool isMappingRead(D3D11_MAP map);
 
 		/// utility method, convert D3D11 pixel format to Ogre pixel format
 		static PixelFormat _getPF(DXGI_FORMAT d3dPF);

+ 1 - 0
CamelotD3D11RenderSystem/Include/CmD3D11Prerequisites.h

@@ -37,6 +37,7 @@ namespace CamelotEngine
 	class D3D11GpuProgramManager;
 	class D3D11HardwareBufferManager;
 	class D3D11HardwareIndexBuffer;
+	class D3D11HardwareConstantBuffer;
 	class D3D11HLSLProgramFactory;
 	class D3D11HLSLProgram;
 	class D3D11VertexDeclaration;

+ 1 - 0
CamelotD3D11RenderSystem/Include/CmD3D11VideoModeList.h

@@ -1,6 +1,7 @@
 #pragma once
 
 #include "CmD3D11Prerequisites.h"
+#include "CmD3D11VideoMode.h"
 
 namespace CamelotEngine
 {

+ 2 - 2
CamelotD3D11RenderSystem/Source/CmD3D11Device.cpp

@@ -80,7 +80,7 @@ namespace CamelotEngine
 		}
 
 		if(doClearErrors)
-			clearError();
+			clearErrors();
 
 		return res;
 	}
@@ -102,7 +102,7 @@ namespace CamelotEngine
 		}
 	}
 
-	void D3D11Device::clearError()
+	void D3D11Device::clearErrors()
 	{
 		if (mD3D11Device != nullptr && mInfoQueue != nullptr)
 		{

+ 2 - 0
CamelotD3D11RenderSystem/Source/CmD3D11HLSLProgram.cpp

@@ -76,5 +76,7 @@ namespace CamelotEngine
 		}
 
 		SAFE_RELEASE(errors);
+
+		return microCode;
 	}
 }

+ 256 - 0
CamelotD3D11RenderSystem/Source/CmD3D11HardwareBuffer.cpp

@@ -0,0 +1,256 @@
+#include "CmD3D11HardwareBuffer.h"
+#include "CmD3D11Mappings.h"
+#include "CmD3D11Device.h"
+#include "CmException.h"
+#include "CmDebug.h"
+
+namespace CamelotEngine
+{
+	D3D11HardwareBuffer::D3D11HardwareBuffer(BufferType btype, UINT32 sizeBytes, HardwareBuffer::Usage usage, 
+		D3D11Device& device, bool useSystemMemory, bool streamOut)
+		: HardwareBuffer(usage, useSystemMemory),
+		mD3DBuffer(0),
+		mpTempStagingBuffer(0),
+		mUseTempStagingBuffer(false),
+		mBufferType(btype),
+		mDevice(device)
+	{
+		mSizeInBytes = sizeBytes;
+		mDesc.ByteWidth = static_cast<UINT>(sizeBytes);
+		
+		mDesc.MiscFlags = 0;
+
+		if (useSystemMemory)
+		{
+			mDesc.Usage = D3D11_USAGE_STAGING;
+			//A D3D11_USAGE_STAGING Resource cannot be bound to any parts of the graphics pipeline, so therefore cannot have any BindFlags bits set.
+			mDesc.BindFlags = 0;
+			mDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ ;// A D3D11_USAGE_STAGING Resource must have at least one CPUAccessFlag bit set.
+
+		}
+		else
+		{
+			mDesc.Usage = D3D11Mappings::_getUsage(mUsage);
+			mDesc.BindFlags = btype == VERTEX_BUFFER ? D3D11_BIND_VERTEX_BUFFER : 
+				btype == INDEX_BUFFER  ? D3D11_BIND_INDEX_BUFFER  :
+				D3D11_BIND_CONSTANT_BUFFER;
+			mDesc.CPUAccessFlags = D3D11Mappings::_getAccessFlags(mUsage); 
+		}
+
+		// Check of stream out flag
+		if (streamOut && btype != CONSTANT_BUFFER)
+		{
+			mDesc.BindFlags |= D3D11_BIND_STREAM_OUTPUT;
+		}
+
+		// TODO: we can explicitly initialise the buffer contents here if we like
+		// not doing this since OGRE doesn't support this model yet
+		HRESULT hr = device.getD3D11Device()->CreateBuffer( &mDesc, nullptr, &mD3DBuffer );
+		if (FAILED(hr) || mDevice.hasError())
+		{
+			String msg = device.getErrorDescription();
+			CM_EXCEPT(RenderingAPIException, "Cannot create D3D11 buffer: " + msg);
+		}
+	}
+
+	D3D11HardwareBuffer::~D3D11HardwareBuffer()
+	{
+		SAFE_RELEASE(mD3DBuffer);
+		SAFE_DELETE(mpTempStagingBuffer); // should never be nonzero unless destroyed while locked
+	}
+
+	void* D3D11HardwareBuffer::lockImpl(UINT32 offset, 
+		UINT32 length, LockOptions options)
+	{
+		if (length > mSizeInBytes)
+			CM_EXCEPT(RenderingAPIException, "Provided length " + toString(length) + " larger than the buffer " + toString(mSizeInBytes) + ".");		
+
+		// Use direct (and faster) Map/Unmap if dynamic write, or a staging read/write
+		if((mDesc.Usage == D3D11_USAGE_DYNAMIC && options != HardwareBuffer::HBL_READ_ONLY) || mDesc.Usage == D3D11_USAGE_STAGING)
+		{
+			D3D11_MAP mapType;
+
+			switch(options)
+			{
+			case HBL_DISCARD:
+				if (mUsage & HardwareBuffer::HBU_DYNAMIC)
+				{
+					// Map cannot be called with MAP_WRITE access, 
+					// because the Resource was created as D3D11_USAGE_DYNAMIC. 
+					// D3D11_USAGE_DYNAMIC Resources must use either MAP_WRITE_DISCARD 
+					// or MAP_WRITE_NO_OVERWRITE with Map.
+					mapType = D3D11_MAP_WRITE_DISCARD;
+				}
+				else
+				{
+					// Map cannot be called with MAP_WRITE_DISCARD access, 
+					// because the Resource was not created as D3D11_USAGE_DYNAMIC. 
+					// D3D11_USAGE_DYNAMIC Resources must use either MAP_WRITE_DISCARD 
+					// or MAP_WRITE_NO_OVERWRITE with Map.
+					mapType = D3D11_MAP_WRITE;
+
+					LOGWRN("DISCARD lock is only available on dynamic buffers. Falling back to normal write.");
+				}
+				break;
+			case HBL_NO_OVERWRITE:
+				if(mBufferType == INDEX_BUFFER || mBufferType == VERTEX_BUFFER)
+					mapType = D3D11_MAP_WRITE_NO_OVERWRITE;
+				else
+				{
+					mapType = D3D11_MAP_WRITE;
+
+					LOGWRN("NO_OVERWRITE lock is not available on this (" + toString(mBufferType) + ") buffer type. Falling back to normal write.");
+				}
+				break;
+			case HBL_NORMAL:
+				if ((mDesc.CPUAccessFlags & D3D11_CPU_ACCESS_READ) != 0 &&
+					(mDesc.CPUAccessFlags & D3D11_CPU_ACCESS_WRITE) != 0)
+				{
+					mapType = D3D11_MAP_READ_WRITE;
+				}
+				else if(mDesc.CPUAccessFlags & D3D11_CPU_ACCESS_WRITE)
+				{
+					mapType = D3D11_MAP_WRITE;
+				}
+				else
+				{
+					mapType = D3D11_MAP_READ;
+				}
+				break;
+			case HBL_READ_ONLY:
+				mapType = D3D11_MAP_READ;
+				break;
+			}
+
+			if(D3D11Mappings::isMappingRead(mapType) && (mDesc.CPUAccessFlags & D3D11_CPU_ACCESS_READ) == 0)
+				CM_EXCEPT(RenderingAPIException, "Trying to read a buffer, but buffer wasn't created with a read access flag.");
+
+			if(D3D11Mappings::isMappingWrite(mapType) && (mDesc.CPUAccessFlags & D3D11_CPU_ACCESS_WRITE) == 0)
+				CM_EXCEPT(RenderingAPIException, "Trying to write to a buffer, but buffer wasn't created with a write access flag.");
+
+			void * pRet = NULL;
+			D3D11_MAPPED_SUBRESOURCE mappedSubResource;
+			mappedSubResource.pData = NULL;
+			mDevice.clearErrors();
+			HRESULT hr = mDevice.getImmediateContext()->Map(mD3DBuffer, 0, mapType, 0, &mappedSubResource);
+			if (FAILED(hr) || mDevice.hasError())
+			{
+				String msg = mDevice.getErrorDescription();
+				CM_EXCEPT(RenderingAPIException, "Error calling Map: " + msg);
+			}
+
+			pRet = static_cast<void*>(static_cast<char*>(mappedSubResource.pData) + offset);
+
+			return pRet;
+		}
+		else // Otherwise create a staging buffer to do all read/write operations on. Usually try to avoid this.
+		{
+			mUseTempStagingBuffer = true;
+			if (!mpTempStagingBuffer)
+			{
+				// create another buffer instance but use system memory
+				mpTempStagingBuffer = new D3D11HardwareBuffer(mBufferType, 
+					mSizeInBytes, mUsage, mDevice, true, false);
+			}
+
+			// schedule a copy to the staging
+			if (options != HBL_DISCARD)
+				mpTempStagingBuffer->copyData(*this, 0, 0, mSizeInBytes, true);
+
+			// register whether we'll need to upload on unlock
+			mStagingUploadNeeded = (options != HBL_READ_ONLY);
+
+			return mpTempStagingBuffer->lock(offset, length, options);
+		}
+	}
+
+	void D3D11HardwareBuffer::unlockImpl(void)
+	{
+		if (mUseTempStagingBuffer)
+		{
+			mUseTempStagingBuffer = false;
+
+			// ok, we locked the staging buffer
+			mpTempStagingBuffer->unlock();
+
+			// copy data if needed
+			// this is async but driver should keep reference
+			if (mStagingUploadNeeded)
+				copyData(*mpTempStagingBuffer, 0, 0, mSizeInBytes, true);
+
+			// delete
+			// not that efficient, but we should not be locking often
+			SAFE_DELETE(mpTempStagingBuffer);
+		}
+		else
+		{
+			// unmap
+			mDevice.getImmediateContext()->Unmap(mD3DBuffer, 0);
+		}
+	}
+
+	void D3D11HardwareBuffer::copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, 
+		UINT32 dstOffset, UINT32 length, bool discardWholeBuffer)
+	{
+		// If we're copying same-size buffers in their entirety...
+		if (srcOffset == 0 && dstOffset == 0 &&
+			length == mSizeInBytes && mSizeInBytes == srcBuffer.getSizeInBytes())
+		{
+			// schedule hardware buffer copy
+			mDevice.getImmediateContext()->CopyResource(mD3DBuffer, static_cast<D3D11HardwareBuffer&>(srcBuffer).getD3DBuffer());
+			if (mDevice.hasError())
+			{
+				String errorDescription = mDevice.getErrorDescription();
+				CM_EXCEPT(RenderingAPIException, "Cannot copy D3D11 resource\nError Description:" + errorDescription);
+			}
+		}
+		else
+		{
+			// copy subregion
+			D3D11_BOX srcBox;
+			srcBox.left = (UINT)srcOffset;
+			srcBox.right = (UINT)srcOffset + length;
+			srcBox.top = 0;
+			srcBox.bottom = 1;
+			srcBox.front = 0;
+			srcBox.back = 1;
+
+			mDevice.getImmediateContext()->CopySubresourceRegion(mD3DBuffer, 0, (UINT)dstOffset, 0, 0, 
+				static_cast<D3D11HardwareBuffer&>(srcBuffer).getD3DBuffer(), 0, &srcBox);
+			if (mDevice.hasError())
+			{
+				String errorDescription = mDevice.getErrorDescription();
+				CM_EXCEPT(RenderingAPIException, "Cannot copy D3D11 subresource region\nError Description:" + errorDescription);
+			}
+		}
+	}
+
+	void D3D11HardwareBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
+	{
+		// There is no functional interface in D3D, just do via manual 
+		// lock, copy & unlock
+		void* pSrc = this->lock(offset, length, HardwareBuffer::HBL_READ_ONLY);
+		memcpy(pDest, pSrc, length);
+		this->unlock();
+	}
+
+	void D3D11HardwareBuffer::writeData(UINT32 offset, UINT32 length, 
+		const void* pSource, bool discardWholeBuffer)
+	{
+		if(mDesc.Usage == D3D11_USAGE_DYNAMIC || mDesc.Usage == D3D11_USAGE_STAGING)
+		{
+			void* pDst = this->lock(offset, length, 
+				discardWholeBuffer ? HardwareBuffer::HBL_DISCARD : HardwareBuffer::HBL_NORMAL);
+			memcpy(pDst, pSource, length);
+			this->unlock();
+		}
+		else if(mDesc.Usage == D3D11_USAGE_DEFAULT)
+		{
+			mDevice.getImmediateContext()->UpdateSubresource(mD3DBuffer, 0, nullptr, pSource, offset, length);
+		}
+		else
+		{
+			CM_EXCEPT(RenderingAPIException, "Trying to write into a buffer with unsupported usage: " + toString(mDesc.Usage));
+		}
+	}
+}

+ 42 - 0
CamelotD3D11RenderSystem/Source/CmD3D11HardwareConstantBuffer.cpp

@@ -0,0 +1,42 @@
+#include "CmD3D11HardwareConstantBuffer.h"
+
+namespace CamelotEngine
+{
+	D3D11HardwareConstantBuffer::D3D11HardwareConstantBuffer(D3D11Device& device, HardwareBufferManagerBase* mgr, UINT32 sizeBytes, 
+		HardwareBuffer::Usage usage, bool useSystemMem)
+		:HardwareConstantBuffer(mgr, sizeBytes, usage, useSystemMem)
+	{
+		mBuffer = new D3D11HardwareBuffer(D3D11HardwareBuffer::CONSTANT_BUFFER, mSizeInBytes, usage, device, useSystemMem, false);
+	}
+
+	D3D11HardwareConstantBuffer::~D3D11HardwareConstantBuffer()
+	{
+		delete mBuffer;
+	}
+
+	void* D3D11HardwareConstantBuffer::lockImpl(UINT32 offset, UINT32 length, LockOptions options)
+	{
+		return mBuffer->lock(offset, length, options);
+	}
+
+	void D3D11HardwareConstantBuffer::unlockImpl()
+	{
+		mBuffer->unlock();
+	}
+
+	void D3D11HardwareConstantBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
+	{
+		mBuffer->readData(offset, length, pDest);
+	}
+
+	void D3D11HardwareConstantBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource, bool discardWholeBuffer)
+	{
+		mBuffer->writeData(offset, length, pSource, discardWholeBuffer);
+	}
+
+	void D3D11HardwareConstantBuffer::copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, 
+		UINT32 dstOffset, UINT32 length, bool discardWholeBuffer)
+	{
+		mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
+	}
+}

+ 42 - 0
CamelotD3D11RenderSystem/Source/CmD3D11HardwareIndexBuffer.cpp

@@ -0,0 +1,42 @@
+#include "CmD3D11HardwareIndexBuffer.h"
+
+namespace CamelotEngine
+{
+	D3D11HardwareIndexBuffer::D3D11HardwareIndexBuffer(D3D11Device& device, HardwareBufferManagerBase* mgr, IndexType idxType, UINT32 numIndexes, 
+		HardwareBuffer::Usage usage, bool useSystemMem)
+		:HardwareIndexBuffer(mgr, idxType, numIndexes, usage, useSystemMem)
+	{
+		mBuffer = new D3D11HardwareBuffer(D3D11HardwareBuffer::INDEX_BUFFER, mSizeInBytes, usage, device, useSystemMem, false);
+	}
+
+	D3D11HardwareIndexBuffer::~D3D11HardwareIndexBuffer()
+	{
+		delete mBuffer;
+	}
+
+	void* D3D11HardwareIndexBuffer::lockImpl(UINT32 offset, UINT32 length, LockOptions options)
+	{
+		return mBuffer->lock(offset, length, options);
+	}
+
+	void D3D11HardwareIndexBuffer::unlockImpl()
+	{
+		mBuffer->unlock();
+	}
+
+	void D3D11HardwareIndexBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
+	{
+		mBuffer->readData(offset, length, pDest);
+	}
+
+	void D3D11HardwareIndexBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource, bool discardWholeBuffer)
+	{
+		mBuffer->writeData(offset, length, pSource, discardWholeBuffer);
+	}
+
+	void D3D11HardwareIndexBuffer::copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, 
+		UINT32 dstOffset, UINT32 length, bool discardWholeBuffer)
+	{
+		mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
+	}
+}

+ 42 - 0
CamelotD3D11RenderSystem/Source/CmD3D11HardwareVertexBuffer.cpp

@@ -0,0 +1,42 @@
+#include "CmD3D11HardwareVertexBuffer.h"
+
+namespace CamelotEngine
+{
+	D3D11HardwareVertexBuffer::D3D11HardwareVertexBuffer(D3D11Device& device, HardwareBufferManagerBase* mgr, UINT32 vertexSize, UINT32 numVertices, 
+		HardwareBuffer::Usage usage, bool useSystemMem)
+		:HardwareVertexBuffer(mgr, vertexSize, numVertices, usage, useSystemMem)
+	{
+		mBuffer = new D3D11HardwareBuffer(D3D11HardwareBuffer::VERTEX_BUFFER, mSizeInBytes, usage, device, useSystemMem, false);
+	}
+
+	D3D11HardwareVertexBuffer::~D3D11HardwareVertexBuffer()
+	{
+		delete mBuffer;
+	}
+
+	void* D3D11HardwareVertexBuffer::lockImpl(UINT32 offset, UINT32 length, LockOptions options)
+	{
+		return mBuffer->lock(offset, length, options);
+	}
+
+	void D3D11HardwareVertexBuffer::unlockImpl()
+	{
+		mBuffer->unlock();
+	}
+
+	void D3D11HardwareVertexBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
+	{
+		mBuffer->readData(offset, length, pDest);
+	}
+
+	void D3D11HardwareVertexBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource, bool discardWholeBuffer)
+	{
+		mBuffer->writeData(offset, length, pSource, discardWholeBuffer);
+	}
+
+	void D3D11HardwareVertexBuffer::copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, 
+		UINT32 dstOffset, UINT32 length, bool discardWholeBuffer)
+	{
+		mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
+	}
+}

+ 17 - 0
CamelotD3D11RenderSystem/Source/CmD3D11Mappings.cpp

@@ -729,6 +729,23 @@ namespace CamelotEngine
 		return _isDynamic(static_cast<HardwareBuffer::Usage>(mUsage));
 	}
 
+	bool D3D11Mappings::isMappingWrite(D3D11_MAP map)
+	{
+		if(map == D3D11_MAP_READ)
+			return false;
+
+		return true;
+
+	}
+
+	bool D3D11Mappings::isMappingRead(D3D11_MAP map)
+	{
+		if(map == D3D11_MAP_READ || map == D3D11_MAP_READ_WRITE)
+			return true;
+
+		return false;
+	}
+
 	D3D11_USAGE D3D11Mappings::_getUsage(int mUsage)
 	{
 		return _getUsage(static_cast<HardwareBuffer::Usage>(mUsage));

+ 1 - 2
CamelotD3D11RenderSystem/Source/CmD3D11VideoModeList.cpp

@@ -1,11 +1,10 @@
 #include "CmD3D11VideoModeList.h"
 #include "CmException.h"
-#include "CmD3D11VideoMode.h"
 #include "CmD3D11Driver.h"
 
 namespace CamelotEngine
 {
-	D3D11VideoModeList::D3D11VideoModeList(D3D11Driver* driver, UINT32 adapterOutput = 0)
+	D3D11VideoModeList::D3D11VideoModeList(D3D11Driver* driver, UINT32 adapterOutput)
 	{
 		if(driver == nullptr)
 			CM_EXCEPT(InvalidParametersException, "driver parameter is NULL");

+ 2 - 0
CamelotRenderer/CamelotRenderer.vcxproj

@@ -192,6 +192,7 @@
     <ClInclude Include="Include\CmGpuProgramRTTI.h" />
     <ClInclude Include="Include\CmHardwareBuffer.h" />
     <ClInclude Include="Include\CmHardwareBufferManager.h" />
+    <ClInclude Include="Include\CmHardwareConstantBuffer.h" />
     <ClInclude Include="Include\CmHardwareIndexBuffer.h" />
     <ClInclude Include="Include\CmHardwareOcclusionQuery.h" />
     <ClInclude Include="Include\CmHardwarePixelBuffer.h" />
@@ -262,6 +263,7 @@
     <ClCompile Include="Source\CmGpuProgramManager.cpp" />
     <ClCompile Include="Source\CmGpuProgramParams.cpp" />
     <ClCompile Include="Source\CmHardwareBufferManager.cpp" />
+    <ClCompile Include="Source\CmHardwareConstantBuffer.cpp" />
     <ClCompile Include="Source\CmHardwareIndexBuffer.cpp" />
     <ClCompile Include="Source\CmHardwareOcclusionQuery.cpp" />
     <ClCompile Include="Source\CmHardwarePixelBuffer.cpp" />

+ 6 - 0
CamelotRenderer/CamelotRenderer.vcxproj.filters

@@ -311,6 +311,9 @@
     <ClInclude Include="Include\CmResourceHandleRTTI.h">
       <Filter>Header Files\RTTI</Filter>
     </ClInclude>
+    <ClInclude Include="Include\CmHardwareConstantBuffer.h">
+      <Filter>Header Files\RenderSystem</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CamelotRenderer.cpp">
@@ -460,5 +463,8 @@
     <ClCompile Include="Source\CmSpecificImporter.cpp">
       <Filter>Source Files\Importer</Filter>
     </ClCompile>
+    <ClCompile Include="Source\CmHardwareConstantBuffer.cpp">
+      <Filter>Source Files\RenderSystem</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 1 - 3
CamelotRenderer/Include/CmHardwareBuffer.h

@@ -122,12 +122,10 @@ namespace CamelotEngine {
                 /** Normal mode, ie allows read/write and contents are preserved. */
                 HBL_NORMAL,
 			    /** Discards the <em>entire</em> buffer while locking; this allows optimisation to be 
-				performed because synchronisation issues are relaxed. Only allowed on buffers 
-			    created with the HBU_DYNAMIC flag. 
+				performed because synchronisation issues are relaxed. 
 			    */
 			    HBL_DISCARD,
 			    /** Lock the buffer for reading only. Not allowed in buffers which are created with HBU_WRITE_ONLY. 
-				Mandatory on static buffers, i.e. those created without the HBU_DYNAMIC flag. 
 				*/ 
 			    HBL_READ_ONLY,
                 /** As HBL_NORMAL, except the application guarantees not to overwrite any 

+ 6 - 2
CamelotRenderer/Include/CmHardwareBufferManager.h

@@ -57,15 +57,17 @@ namespace CamelotEngine {
 	class CM_EXPORT HardwareBufferManagerBase
 	{
     protected:
-        /** WARNING: The following two members should place before all other members.
+        /** WARNING: The following three members should place before all other members.
             Members destruct order is very important here, because destructing other
             members will cause notify back to this class, and then will access to this
             two members.
         */
         typedef set<HardwareVertexBuffer*>::type VertexBufferList;
         typedef set<HardwareIndexBuffer*>::type IndexBufferList;
+		typedef set<HardwareConstantBuffer*>::type ConstantBufferList;
         VertexBufferList mVertexBuffers;
         IndexBufferList mIndexBuffers;
+		ConstantBufferList mConstantBuffers;
 
 		typedef set<VertexBufferBinding*>::type VertexBufferBindingList;
 		VertexBufferBindingList mVertexBufferBindings;
@@ -73,6 +75,7 @@ namespace CamelotEngine {
 		// Mutexes
 		CM_MUTEX(mVertexBuffersMutex)
 		CM_MUTEX(mIndexBuffersMutex)
+		CM_MUTEX(mConstantBuffersMutex)
 		CM_MUTEX(mVertexBufferBindingsMutex)
 
         /// Internal method for destroys all vertex buffer bindings
@@ -151,7 +154,8 @@ namespace CamelotEngine {
 		void _notifyVertexBufferDestroyed(HardwareVertexBuffer* buf);
 		/// Notification that a hardware index buffer has been destroyed
 		void _notifyIndexBufferDestroyed(HardwareIndexBuffer* buf);
-
+		/// Notification that a hardware constant buffer has been destroyed
+		void _notifyConstantBufferDestroyed(HardwareConstantBuffer* buf);
 	};
 
     /** Singleton wrapper for hardware buffer manager. */

+ 21 - 0
CamelotRenderer/Include/CmHardwareConstantBuffer.h

@@ -0,0 +1,21 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmHardwareBuffer.h"
+
+namespace CamelotEngine
+{
+	class CM_EXPORT HardwareConstantBuffer : public HardwareBuffer
+	{
+	protected:
+		HardwareBufferManagerBase* mMgr;
+
+	public:
+		/// Should be called by HardwareBufferManager
+		HardwareConstantBuffer(HardwareBufferManagerBase* mgr, UINT32 sizeBytes, HardwareBuffer::Usage usage, bool useSystemMemory);
+		~HardwareConstantBuffer();
+
+		/// Return the manager of this buffer, if any
+		HardwareBufferManagerBase* getManager() const { return mMgr; }
+	};
+}

+ 2 - 0
CamelotRenderer/Include/CmPrerequisites.h

@@ -107,6 +107,8 @@ namespace CamelotEngine {
 	class PassParameters;
 	class RenderSystemContext;
 	class AsyncOp;
+	class HardwareBufferManagerBase;
+	class HardwareConstantBuffer;
 	// Asset import
 	class SpecificImporter;
 	class Importer;

+ 13 - 0
CamelotRenderer/Source/CmHardwareBufferManager.cpp

@@ -28,6 +28,7 @@ THE SOFTWARE.
 
 #include "CmHardwareBufferManager.h"
 #include "CmVertexIndexData.h"
+#include "CmHardwareConstantBuffer.h"
 
 
 namespace CamelotEngine {
@@ -53,6 +54,7 @@ namespace CamelotEngine {
         // unnecessary work, and we'll destroy everything here.
 		mVertexBuffers.clear();
 		mIndexBuffers.clear();
+		mConstantBuffers.clear();
 
         // Destroy everything
         destroyAllBindings();
@@ -130,4 +132,15 @@ namespace CamelotEngine {
 			mIndexBuffers.erase(i);
 		}
 	}
+	//-----------------------------------------------------------------------
+	void HardwareBufferManagerBase::_notifyConstantBufferDestroyed(HardwareConstantBuffer* buf)
+	{
+		CM_LOCK_MUTEX(mConstantBuffersMutex)
+
+		ConstantBufferList::iterator i = mConstantBuffers.find(buf);
+		if (i != mConstantBuffers.end())
+		{
+			mConstantBuffers.erase(i);
+		}
+	}
 }

+ 20 - 0
CamelotRenderer/Source/CmHardwareConstantBuffer.cpp

@@ -0,0 +1,20 @@
+#include "CmHardwareConstantBuffer.h"
+#include "CmHardwareBufferManager.h"
+
+namespace CamelotEngine
+{
+	HardwareConstantBuffer::HardwareConstantBuffer(HardwareBufferManagerBase* mgr, UINT32 sizeBytes, HardwareBuffer::Usage usage, bool useSystemMemory)
+		: HardwareBuffer(usage, useSystemMemory)
+	{
+		// Calculate the size of the vertices
+		mSizeInBytes = sizeBytes;
+	}
+
+	HardwareConstantBuffer::~HardwareConstantBuffer()
+	{
+		if (mMgr)
+		{
+			mMgr->_notifyConstantBufferDestroyed(this);
+		}
+	}
+}